cmd1 = "uxterm -e aria2 ..."
subprocess.call(cmd1, shell=True)
cmd2 = "mplayer ..."
subprocess.call(cmd2, shell=True)
像上面那样,必须cmd1结束后才开始运行cmd2,我想要cmd1和cmd2同时运行,该怎么办?
也就是cmd1打开一个xterm窗口让它去执行aria2下载的同时,cmd2这边的mplayer也能同时执行。
初学python的新手,请多指教。
Python如何同时运行多个shell命令?
-
- 帖子: 408
- 注册时间: 2009-05-29 15:21
- vickycq
- 帖子: 4507
- 注册时间: 2011-03-20 13:12
- 系统: Debian
- 来自: 山东省寿光县
- 联系:
Re: Python如何同时运行多个shell命令?
http://stackoverflow.com/questions/1639 ... rom-python
http://stackoverflow.com/questions/4992 ... n-parallel
http://stackoverflow.com/questions/1645 ... n-parallel
http://stackoverflow.com/questions/7681 ... i-use-them
http://stackoverflow.com/questions/4992 ... n-parallel
http://stackoverflow.com/questions/1645 ... n-parallel
http://stackoverflow.com/questions/7681 ... i-use-them
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
欢迎所有 Debian GNU/Linux 用户
-
- 帖子: 65
- 注册时间: 2009-11-25 1:38
Re: Python如何同时运行多个shell命令?
使用 Popen(), 不要用 call() 就可以
- hceasy
- 论坛版主
- 帖子: 6009
- 注册时间: 2010-04-17 18:51
- 系统: W10
Re: Python如何同时运行多个shell命令?
import threading
cmd1 = threading.Thread(target=shell1)
threads.append(cmd1)
cmd2 = threading.Thread(target=shell2)
threads.append(cmd1)
for t in GLOBAL_VAR.threads:
t.start()
t.join()
如果有同时读取一个变量的操作 注意用原子锁
cmd1 = threading.Thread(target=shell1)
threads.append(cmd1)
cmd2 = threading.Thread(target=shell2)
threads.append(cmd1)
for t in GLOBAL_VAR.threads:
t.start()
t.join()
如果有同时读取一个变量的操作 注意用原子锁