Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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()
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