子进程的键盘中断。运行()

2024-09-24 20:38:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Python代码,其中我使用subprocess.run()来调用10次(迭代)外部大量模拟,模拟大约进行40次迭代。所以,我有10*40=400次模拟运行。我的问题是,尽管在某种程度上整个流程运行平稳,但几个小时后,我收到了一个与子流程相关的错误。run()

Traceback (most recent call last):
  File "Desktop/ChargersDanielWithInput.py", line 63, in <module>
    subprocess.run(["/zhome/c9/f/144817/apache-maven-3.6.3/bin/mvn", "exec:java", "-Dexec.mainClass=org.matsim.contrib.ev.example.MyRunEvExample", "-Dexec.args=/work3/s175836/Scenarios/Scenario_1/Input/config_test_daniel.xml", "-Dexec.cleanupDaemonThreads=false"])
  File "/appl/python/3.8.4/lib/python3.8/subprocess.py", line 491, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
  File "/appl/python/3.8.4/lib/python3.8/subprocess.py", line 1016, in communicate
    self.wait()
  File "/appl/python/3.8.4/lib/python3.8/subprocess.py", line 1079, in wait
    return self._wait(timeout=timeout)
  File "/appl/python/3.8.4/lib/python3.8/subprocess.py", line 1804, in _wait
    (pid, sts) = self._try_wait(0)
  File "/appl/python/3.8.4/lib/python3.8/subprocess.py", line 1762, in _try_wait
    (pid, sts) = os.waitpid(self.pid, wait_flags)
KeyboardInterrupt

这里非常奇怪的一点是,这个错误不会在subprocess.run()的第一次调用时出现,但它会在整个模拟过程中的某个时刻出现。我真的不知道为什么会这样。 现在,我已经将subprocess.run()替换为os.system(),希望仔细检查是否是subprocess.run()命令引起了问题


Tags: runinpyselflib错误linetimeout