我有一个处理大量文件的python程序,其中一个步骤是通过一个.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命令(我在Windows10上),并且不会在出现错误时停止。但是,有一个特定的错误会停止我的python程序的执行。我认为这是因为.jar文件并没有真正停止,仍然在后台运行,从而阻止了python继续运行。
我有没有办法在Python中调用命令并异步运行,或者在20秒超时后跳过它?我也可以编写一个Java程序来运行该过程的这一部分,但为了方便起见,我更喜欢将所有内容都放在Python上
为了以防万一,我将把停止我的程序的错误放在这里(所有其他的都会被try: except:正确捕获)
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)发布于 2021-02-25 17:03:38
在查看了深入的子流程文档后,我发现了一个名为timeout的参数:
subprocess.check_call('...', stdout=subprocess.DEVNULL, timeout=20)它能帮我做这件事
https://stackoverflow.com/questions/66364209
复制相似问题