Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13921

input() function breaks Process invocation in Python with multiprocessing module

$
0
0

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:

print1

The process p is never called. But if I remove the line with the input() function, the program runs as expected:

print2

Why is this happening? How can I fix this?I'm running this code inside PyCharm IDE in Windows 10.


Viewing all articles
Browse latest Browse all 13921

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>