Skip to content

Instantly share code, notes, and snippets.

@IgorHalfeld
Last active July 26, 2017 16:15
Show Gist options
  • Save IgorHalfeld/952533bbfe82e4deab30c26edbb986c6 to your computer and use it in GitHub Desktop.
Save IgorHalfeld/952533bbfe82e4deab30c26edbb986c6 to your computer and use it in GitHub Desktop.
# Example shown on this video
# https://www.youtube.com/watch?v=GPz49npOKzQ
# that I re-written in python
#
# Python 3 is required
import threading
import time
thread_group = []
def hard_task(name):
for number in range(1, 10):
time.sleep(1)
print('Hard task {}...'.format(name))
print('Hard task {} Done!'.format(name))
def handle_all_threads():
for thread in thread_group:
thread.join()
print('All tasks Done!')
def init():
for i in range(1, 10):
thread = threading.Thread(
target = hard_task,
args = (str(i))
)
thread.start()
thread_group.append(thread)
handle_all_threads()
init()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment