Reputation: 1076
I'm having an issue getting started using Python's Multiprocessing library.
When I run one of the most basic examples (shown below) I don't get anything to print to the console:
from multiprocessing import Process
def f(name):
print('hello', name)
if __name__ == '__main__':
p = Process(target=f, args=('bob',))
p.start()
p.join()
I was expecting to see hello bob
but instead it hung for a moment before eventually finishing and printing nothing to the console.
Here's the command that is run by VSCode when I hit F5. My code (shown above) is in a file at QueueTrigger1/__init__.py
I'm running python ver 3.9.5 (here's the printout from just running python)
Any assistance on why my Multiprocess isn't spawning would be greatly appreciated
Upvotes: 0
Views: 101
Reputation: 1076
Turns out I'd placed this code at the top of a longer .py file full of code.
I'd put an exit()
at the bottom of my testing code thinking it would simply hide the other code in the rest of my .py file.
This exit()
statment ended up making the child process not run correctly. Thanks for @DanielWalker for the tip.
The solution was to remove the exit statement and cleanup the rest of the file.
Upvotes: 1