我有以下 Python 代码段,无法解释为什么它的行为方式如此。
import subprocess
bash1 = subprocess.Popen(["/bin/bash","-l", "-i"], stdin=subprocess.PIPE)
print "Checkpoint 1"
bash2 = subprocess.Popen(["/bin/bash","-l", "-i"], stdin=subprocess.PIPE)
print "Checkpoint 2"
bash1.communicate("echo 'works1'")
bash2.communicate("echo 'works2'")
print "OK"
当我运行它时,我得到以下输出:
[user@localhost ~]$ python test.py
Checkpoint 1
Checkpoint 2
[1]+ Stopped python test.py
[user@localhost ~]$ [user@localhost ~]$ echo 'works1'
works1
[user@localhost ~]$ logout
[user@localhost ~]$ fg
python test.py
[user@localhost ~]$ echo 'works2'
works2
[user@localhost ~]$ logout
OK
[user@localhost ~]$
- 为什么 Python 进程在第二次 Popen 调用时停止?(由 tty 输入停止),以及如何避免它?
- 为什么在 echo 'works1' 完成后我会收到注销消息,以及如何避免它?