Created
April 27, 2020 06:53
-
-
Save michaelbukachi/97f874247e7f098135d095c0a7d11f4d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 func1(): | |
print('Starting func 1') | |
end_time = time.time() + 5 | |
i = 0 | |
while time.time() < end_time: | |
i += 1 | |
print(f'func 1 counted {i}') | |
print('func 1 done') | |
def func2(): | |
print('Starting func 2') | |
end_time = time.time() + 5 | |
i = 0 | |
while time.time() < end_time: | |
i += 1 | |
print(f'func 2 counted {i}') | |
print('func 2 done') | |
def func3(): | |
print('Starting func 3') | |
end_time = time.time() + 5 | |
i = 0 | |
while time.time() < end_time: | |
i += 1 | |
print(f'func 3 counted {i}') | |
print('func 3 done') | |
if __name__ == '__main__': | |
threads = [ | |
threading.Thread(target=func1), | |
threading.Thread(target=func2), | |
threading.Thread(target=func3) | |
] | |
for thread in threads: | |
thread.start() | |
for thread in threads: | |
thread.join() |
This file contains hidden or 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 time | |
if __name__ == '__main__': | |
end_time = time.time() + 5 | |
i = 0 | |
while time.time() < end_time: | |
i += 1 | |
print(f'counted {i}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment