所以我有一个程序,在“main”进程中,我启动了一个新的Process对象(我想要的)是从STDIN读取行并将它们附加到Queue对象。在子进程中使用STDIN的Python
本质上来说,基本的系统设置是有一个“命令获取”过程,用户将输入命令/查询,并且我需要将这些查询提供给运行在不同进程中的其他子系统。我的想法是通过其他系统可读取的多处理队列来共享这些队列。
我所(侧重于刚刚得到的命令/查询)基本上是:
def sub_proc(q):
some_str = ""
while True:
some_str = raw_input("> ")
if some_str.lower() == "quit":
return
q.put_nowait(some_str)
if __name__ == "__main__":
q = Queue()
qproc = Process(target=sub_proc, args=(q,))
qproc.start()
qproc.join()
# now at this point q should contain all the strings entered by the user
的问题是,我得到:
Process Process-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
File "/home/blah/blah/blah/blah.py", line 325, in sub_proc
some_str = raw_input("> ")
File "/randompathhere/eclipse/plugins/org.python.pydev_2.1.0.2011052613/PySrc/pydev_sitecustomize/sitecustomize.py", line 181, in raw_input
ret = original_raw_input(prompt)
EOFError: EOF when reading a line
怎么办?
相关:[有没有办法将'stdin'作为参数传递给python中的另一个进程? /8976962](https://stackoverflow.com/questions/8976962/is-there-any-way-to-pass-stdin-as-an-argument-to-another-process-in-python/) – n611x007
note [评论](https://stackoverflow.com/questions/8976962/is-there-any-way-to-pass-stdin-as-an-argument-to-another-process-in-python/8981813#comment11253203_8976962)的(http://stackoverflow.com/users/24718/monkut):“类似于[你如何从Python中的stdin读取?/1450393](http://stackoverflow.com/questions/1450393/如何从Python读取stdin)“ – n611x007