0

I am writing a 2-process program to echo a line of raw input while heartbeat once every second.

Here is the code:

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()

When I run this script, there is always an EOFError thrown.

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

What is wrong here? How to correct this?

alvinzoo
  • 493
  • 2
  • 8
  • 17

0 Answers0