簡體   English   中英

如何避免 Python 子進程停止執行

[英]How to avoid Python Subprocess stopping execution

我有一個處理大量文件的 python 程序,通過 a.JAR 文件進行一步我目前有類似的東西

    for row in rows:
        try:
            subprocess.check_call(f'java -jar ffdec/ffdec.jar -export png "{out_dir}/" "{row[0]}.swf", stdout=subprocess.DEVNULL)
        except (OSError, subprocess.SubprocessError, subprocess.CalledProcessError):
            print(f"Error on {row[0]}")
            continue

這適用於執行 os 命令(我在 Windows 10 上)並且不會因錯誤而停止。 但是,有一個特定錯誤會停止執行我的 python 程序。 我認為這是因為 .jar 文件並沒有真正停止,並且仍然在后台運行,從而阻止了 python 繼續。

我有辦法在 Python 中調用命令並異步運行它,還是在 20 秒超時后跳過它? 我也可以制作一個 Java 程序來運行該過程的一部分,但為了方便起見,我更喜歡在 Python 上運行

以防萬一,我將把停止我的程序的錯誤放在這里(所有其他的都被try正確捕獲:除了:)

f�vr. 25, 2021 8:05:00 AM com.jpexs.decompiler.flash.console.ConsoleAbortRetryIgnoreHandler handle
GRAVE: Error occured
java.util.EmptyStackException
    at java.util.Stack.peek(Unknown Source)
    at com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter.addUse(SVGExporter.java:230)
    at com.jpexs.decompiler.flash.timeline.Timeline.toSVG(Timeline.java:1043)
    at com.jpexs.decompiler.flash.exporters.FrameExporter.lambda$exportFrames$0(FrameExporter.java:216)
    at com.jpexs.decompiler.flash.RetryTask.run(RetryTask.java:41)
    at com.jpexs.decompiler.flash.exporters.FrameExporter.exportFrames(FrameExporter.java:220)
    at com.jpexs.decompiler.flash.console.CommandLineArgumentParser.parseExport(CommandLineArgumentParser.java:2298)
    at com.jpexs.decompiler.flash.console.CommandLineArgumentParser.parseArguments(CommandLineArgumentParser.java:891)
    at com.jpexs.decompiler.flash.gui.Main.main(Main.java:1972)

在查看了深度子流程文檔后,發現了一個叫超時的參數:

subprocess.check_call('...', stdout=subprocess.DEVNULL, timeout=20)

那可以為我做這項工作

超時文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM