Mar-23-2021, 06:15 PM
(This post was last modified: Mar-23-2021, 06:15 PM by stylingpat.)
Hey guys, I'm learning about multiprocessing. If I run this code, I don't get the print "Sleeping for 1 second". But if I run the line do_something(), I'll get both prints. Any reason why? It doesnt do it with Anaconda or IDLE.
import multiprocessing
import time
start = time.perf_counter()
def do_something():
print('Sleeping for 1 second')
time.sleep(1)
print('Done sleeping...')
if __name__ == '__main__':
p1 = multiprocessing.Process(target=do_something)
p2 = multiprocessing.Process(target=do_something)
p1.start()
p2.start()
p1.join()
p2.join
finish = time.perf_counter()
print(f'Finished in {round(finish-start,4)} seconds')Here's my outputsOutput:runfile('C:/Users/zenfi/OneDrive/Desktop/multiprocessing/conda_testing.py', wdir='C:/Users/zenfi/OneDrive/Desktop/multiprocessing')
Finished in 1.079 seconds
do_something()
Sleeping for 1 second
Done sleeping...

That block of code is a blur to my eyes and brain. Its not because its intellectually out of reach, that my brain cant process the connections. Its the way its presented. Everything in that block of code is too similar.