Skip to content

Instantly share code, notes, and snippets.

@rainyman2012
Created September 3, 2021 10:51
Show Gist options
  • Save rainyman2012/0e3136efb8a9bf167f57a91df624b121 to your computer and use it in GitHub Desktop.
Save rainyman2012/0e3136efb8a9bf167f57a91df624b121 to your computer and use it in GitHub Desktop.
import threading
import time
def blocking_1():
print("thread start 1")
time.sleep(10)
print("thread finished 1")
def blocking_2():
print("thread start 2")
time.sleep(5)
print("thread finished 2")
def blocking_3():
print("thread start 3")
time.sleep(8)
print("thread finished 3")
def main():
t1 = threading.Thread(target=blocking_1, name="blocking_task")
t2 = threading.Thread(target=blocking_2, name="blocking_task")
t3 = threading.Thread(target=blocking_3, name="blocking_task")
t1.start()
t2.start()
t3.start()
t1.join()
t2.join()
t3.join()
start_time = time.perf_counter()
main()
print("process exited")
end_time = time.perf_counter()
execution_time = end_time - start_time
print(f"\nExecuting - {__file__}\nExecution Starts: {start_time}\nExecutions Ends: {end_time}\nTotals Execution Time:{execution_time:0.2f} seconds.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment