Last active
July 26, 2017 16:15
-
-
Save IgorHalfeld/952533bbfe82e4deab30c26edbb986c6 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
# 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