Python子进程通信杀死了我的进程 [英] Python subprocess communicate kills my process
本文介绍了Python子进程通信杀死了我的进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么通信会杀死我的进程?我想要一个交互式过程,但通信做了一些事情,所以我不能在我的过程中再使用 raw_input.
Why does communicate kill my process? I want an interactive process but communicate does something so that I cannot take raw_input any more in my process.
from sys import stdin
from threading import Thread
from time import sleep
if __name__ == '__main__':
print("Still Running\n")
x = raw_input()
i = 0
while ('n' not in x ) :
print("Still Running " + str(i) + " \r\n")
x = raw_input()
i += 1
print("quit")
print(aSubProc.theProcess.communicate('y'))
print(aSubProc.theProcess.communicate('y'))
例外!
self.stdin.write(input)
ValueError: I/O operation on closed file
推荐答案
communicate
和 wait
对象的Popen
方法,关闭PIPE
进程返回后.如果您想与流程保持沟通,请尝试以下操作:
communicate
and wait
methods of Popen
objects, close the PIPE
after the process returns. If you want stay in communication with the process try something like this:
import subprocess
proc = subprocess.Popen("some_process", stdout=subprocess.PIPE, stdin=subprocess.PIPE)
proc.stdin.write("input")
proc.stdout.readline()
这篇关于Python子进程通信杀死了我的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文