Skip to content

Instantly share code, notes, and snippets.

@michaelbukachi
Created April 27, 2020 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelbukachi/97f874247e7f098135d095c0a7d11f4d to your computer and use it in GitHub Desktop.
Save michaelbukachi/97f874247e7f098135d095c0a7d11f4d to your computer and use it in GitHub Desktop.
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