0

I'm getting "EOFError: EOF when reading a line", when I try to take input.

def one():
    xyz = input("enter : ")
    print(xyz)

    time.sleep(1)

if __name__=='__main__':
    from multiprocessing import Process
    import time

    p1 = Process(target = one)
    p1.start()
user1779646
  • 809
  • 1
  • 8
  • 21

1 Answers1

1

the main process owns standard input, the forked process doesn't.

What would work would be to use multiprocessing.dummy which doesn't create subprocesses but threads.

def one(stdin):
    xyz = input("enter: ")
    print(xyz)

    time.sleep(1)

if __name__=='__main__':
    from multiprocessing.dummy import Process
    import time

    p1 = Process(target = one)
    p1.start()

since threads share the process, they also share standard input.

for real multiprocessing, I suggest that you collect interactive input from main process and pass it as argument.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219