The below code raises an EOF exception on the input statement.
from multiprocessing import Process
def mainloop():
while True:
print("drawing board")
movement = input("direction")
if movement != "":
print(movement)
print("user move")
if __name__ == "__main__":
m = Process(target=mainloop)
m.start()
m.join()
output
drawing board
directionProcess Process-1:
Traceback (most recent call last):
File "C:Python38libmultiprocessingprocess.py", line 315, in _bootstrap
self.run()
File "C:Python38libmultiprocessingprocess.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "c:UsersGaMeRDesktopGamesDiscord bot gameisolation.py", line 5, in mainloop
movement = input("direction")
EOFError: EOF when reading a line
although if mainloop is executed in the current thread, the error does not occur
def mainloop():
while True:
print("drawing board")
movement = input("direction")
if movement != "":
print(movement)
print("user move")
mainloop()
output:
drawing board
direction1
1
user move
drawing board
Advertisement
Answer
The problem cannot be solved. I have looked online and the only other thign that is related to this is this other stackoverflow question.https://stackoverflow.com/questions/42837544/python-3-multiprocessing-eoferror-eof-when-reading-a-line. Basically what is happening is the normal sys.stdin() that input uses is forbidden by multithreading, usually people can sidestep this by using the threading module. Sadly this is not possible because the two need to run together or they will both fail. If you execute this in the IDLE it will not show any text at all, I still have no idea why this happens. If you want this there is no current solution