I've got a system that needs to receive input from a few different processes. The simplest is just a command line where the user enters data manually. This data will be added to a multiprocessing.Queue
and handled later by the main process, but I'm not even getting that far; calling raw_input
inside a process doesn't seem to work. I pulled out the meat of the code and here's an example:
import multiprocessing
def f():
while True:
raw_input('>>>')
p = multiprocessing.Process(target = f)
p.start()
This simple code throws this:
~$ python test.py
Process Process-1:
Traceback (most recent call last):
File "/usr/lib/python2.6/multiprocessing/process.py", line 232, in _bootstrap
self.run()
File "/usr/lib/python2.6/multiprocessing/process.py", line 88, in run
self._target(*self._args, **self._kwargs)
File "test.py", line 5, in f
raw_input('>>>')
EOFError: EOF when reading a line
>>>~$
How can I get command line input in a process in Python?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…