I am currently learning how to use multiprocessing from Corey Schafer's YouTube video: https://www.youtube.com/watch?v=fKl2JW_qrso&ab_channel=CoreySchafer
I am at the 10-minute mark on the video and I had copied my codes exactly like what was shown in the video but the results I have gotten are frustratingly different.
import time
import multiprocessing
def do_something():
print('Sleeping 1 second....')
time.sleep(1)
print('Done Sleeping...')
start = time.perf_counter()
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, 2)} second(s)')
The result should've been:
Sleeping 1 second...
Sleeping 1 second...
Done Sleeping...
Done Sleeping...
Finished in 1.01 second(s)
But what I've gotten instead is:
Finished in 0.48 second(s)
It did not even print the 'Sleeping 1 second...' and 'Done Sleeping...' thing. So I'm guessing the function in the multiprocessing thing didn't even run?? Does anyone know the reason why my python code is behaving this way? Any help is much appreciated. Thanks
