This is because stdin closes before starting the process. Otherwise, it may happen that both the parent and the child processes (or several child processes) try to read from the same stdin, which is a bad idea.
In the child process, sys.stdin actually redirected to /dev/null :
from multiprocessing import Process import sys def test(*args): print(args) print(sys.stdin, sys.stdin.fileno()) if __name__ == '__main__': p = Process(target=test, args=(sys.stdin,)) p.start() p.join()
should print something similar to this:
(<closed file '<stdin>', mode 'r' at 0x7f3b4564b0c0>,) (<open file '/dev/null', mode 'r' at 0x7f3b43a9e0c0>, 3)
The past argument here is a reference to a private file object, trying to use it will result in the error you saw.
You can get around this by using os.dup() in sys.stdin.fileno() in the parent object and pass the returned copy of the file descriptor to child as an argument, where you can use os.fdopen() to work with it.
A cleaner solution would probably be to read the input in the parent process and pass it to the child using multiprocessing.Queue .
source share