Last active
July 24, 2017 15:15
-
-
Save BassyKuo/2f9ba7cc1ec728a2bf5f771f07a0127c to your computer and use it in GitHub Desktop.
hello_threading.py
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
#!/usr/bin/env python3 | |
import threading | |
num_threads = 5 | |
th = {} | |
def main(): | |
for th_id in range(num_threads): | |
th[th_id] = threading.Thread(target=show, args=(th_id,)) | |
th[th_id].start() | |
# --- [ Waiting for all threads | |
for th_id in range(num_threads): | |
th[th_id].join() | |
# --- [ After all threads done | |
print ('===THE END===') | |
def show(idx): | |
print ('Hello Thread-{}'.format(idx)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment