调用Process.start()时带有raw_input()的Python EOFError

时间:2016-03-16 14:49:04

标签: python linux exception multiprocessing

我正在编写一个2进程程序来回应一行原始输入,而心跳每秒一次。

以下是代码:

from multiprocessing import Process
import time

def echo():
    while True:
        a = raw_input('type something')
        print 'you typed: ', a

def ticking():
    while True:
        time.sleep(1)
        print 'hello'

if __name__ == '__main__':
    p1 = Process(target=echo, args=())
    p1.start()

    p2 = Process(target=ticking, args=())
    p2.start()

    p1.join()
    p2.join()

当我运行此脚本时,总会抛出一个EOFError。

Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/process.py", line 114, in run
self._target(*self._args, **self._kwargs)
  File "t.py", line 7, in echo
a = raw_input('type something')
EOFError: EOF when reading a line

这里有什么问题?如何纠正这个?

0 个答案:

没有答案