import multiprocessing
import os
# Creating the tuple of all the processes which can be run in parallel
all_parallel_processes = ('script_A.py', 'script_B.py', 'script_C.py')
next_run = ('script_D.py')
# This block of code enables us to call the script from command line.
def execute(process):
os.system(f'python {process}')
process_pool = Pool(processes = 4)
process_pool.map(execute, all_parallel_processes)
process_pool.map(execute, next_run)
我的答案是基于这个link
假设在单独的脚本中有这些命令,可以执行以下操作:
它们只在脚本之后运行。在
最后我找到了一个简单的解决办法
(一)
在os.chdir公司(“C:\RTM3Run_Full\Python Codes”)
在操作系统(“2015年第64期)_碰撞.bat“)
(二)
我在射程内(设置.loop): .... 在
这保证在第1)部分完成后运行第2)部分。在
~
os.startfile
模拟浏览器中的单击。这意味着批处理文件将在后台运行。在替换此项:
通过适当的阻塞子进程调用,并且由于它是一个批处理文件,并且您希望避免
^{pr2}$shell=True
,前缀为cmd /c
,作为参数列表。也不要chdir
,只需使用current working directory参数,这样当前目录不会更改:您可能需要检查返回代码,或者在批处理文件返回非零退出代码时使用
check_call
停止并出现异常。在相关问题 更多 >
编程相关推荐