user1779646
user1779646

Reputation: 819

Python multiprocess

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

Upvotes: 0

Views: 69

Answers (1)

Jean-François Fabre
Jean-François Fabre

Reputation: 140168

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.

Upvotes: 1

Related Questions