34 lines
630 B
Python
34 lines
630 B
Python
import multiprocessing
|
|
import threading
|
|
import time
|
|
|
|
start = time.perf_counter()
|
|
|
|
def do_something():
|
|
print("Start sleeping")
|
|
time.sleep(1)
|
|
print("awake")
|
|
|
|
threads = []
|
|
|
|
for _ in range(5):
|
|
p = threading.Thread(target=do_something)
|
|
p.start()
|
|
threads.append(p)
|
|
|
|
for t in threads :
|
|
t.join()
|
|
|
|
#p1 = multiprocessing.Process(target=do_something)
|
|
#p2 = multiprocessing.Process(target=do_something)
|
|
#p1 = threading.Thread(target=do_something)
|
|
#p2 = threading.Thread(target=do_something)
|
|
#p1.start()
|
|
#p2.start()
|
|
#p1.join()
|
|
#p2.join()
|
|
|
|
ended = time.perf_counter()
|
|
|
|
|
|
print(f' Duration {round(ended - start,2)} s') |