I wrote this simple code in Python 3.11 to learn the multiprocessing module:
from multiprocessing import Processimport timedef proc(text): while True: print(text) time.sleep(1)print(__name__)if __name__ == '__main__': p = Process(target=proc, args=('hi',)) p.start() input('Press any key to exit') p.terminate()
The idea is for process p to keep printing a text until the main process calls p.terminate().
But when I run this code, here's what I get:
The process p is never called. But if I remove the line with the input() function, the program runs as expected:
Why is this happening? How can I fix this?I'm running this code inside PyCharm IDE in Windows 10.