0% found this document useful (0 votes)
2 views1 page

Python Threading Example Code

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Python Threading Example Code

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import time

start = time.perf_counter()

def do_something():
print("sleeping for 1 second")
[Link](1)
print("done sleeping")

do_something()
do_something()
finish = time.perf_counter()
print(f"finished in {round(finish - start, 2)} seconds")

======================

import _thread
import threading
import time

start = time.perf_counter()

def do_something():
print("sleeping for 1 second")
[Link](1)
print("done sleeping")

threads = []
for _ in range(10):
t = [Link](target=do_something)
[Link]()
[Link](t)

for thread in threads:


[Link]()

finish = time.perf_counter()

print(f"finished in {round(finish - start, 2)} seconds")

You might also like