如何避免 Python 子进程停止执行
How to avoid Python Subprocess stopping execution
我有一个处理很多文件的 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 命令(我在 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[=12=](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)
深入查看子流程文档后,我发现了一个名为 timeout 的参数:
subprocess.check_call('...', stdout=subprocess.DEVNULL, timeout=20)
那可以帮我完成工作
我有一个处理很多文件的 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 命令(我在 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[=12=](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)
深入查看子流程文档后,我发现了一个名为 timeout 的参数:
subprocess.check_call('...', stdout=subprocess.DEVNULL, timeout=20)
那可以帮我完成工作