Created
September 3, 2021 10:51
-
-
Save rainyman2012/0e3136efb8a9bf167f57a91df624b121 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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