import time
from multiprocessing import Process
start = time.perf_counter()
def sleep():
print('Sleeping 1 second(s)...')
time.sleep(1)
return 'Done Sleeping...'
p1 = Process(target = sleep)
p2 = Process(target = sleep)
p1.start()
p2.start()
p1.join()
p2.join()
finish = time.perf_counter()
print(f'Finished in {round(finish-start, 2)} second(s)')
output:
Finished in 0.17 second(s)
I tried to use multiprocessing, but when I run the code it`s over in 0.17~ seconds and not 1 as it supposed to be, it's not sets off the function at all...
If I will put brackets like this :
p1 = Process(target = sleep())
p2 = Process(target = sleep())
output:
Sleeping 1 second(s)...
Sleeping 1 second(s)...
Finished in 2.35 second(s)
windows 10. python 3.7.4 thank you:)