简体   繁体   English

在python中执行并行命令

[英]execute parallel command in python

I'm trying to execute multiple linux commands using Python. 我正在尝试使用Python执行多个Linux命令。 Currently my script is 目前我的脚本是

    import os
    os.system('cmd1')
    os.system('cmd2')
    os.system('cmd3')
    os.system('cmd4')

I'm wondering if there's a way to execute cmd1 and cmd2 in parallel. 我想知道是否有一种方法可以并行执行cmd1和cmd2。 After cmd1 and cmd2 finishes, the system will execute cmd3 and cmd4? cmd1和cmd2完成后,系统将执行cmd3和cmd4吗? Thanks! 谢谢!

Use os.fork() and run the two system commands in two children. 使用os.fork()并在两个子代中运行两个系统命令。 Use os.waitpid() on the two children before executing cmd3. 在执行cmd3之前,在两个子节点上使用os.waitpid()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM