Created
March 6, 2018 10:28
-
-
Save cdpath/e972521539ad1aedc26b10bf72df6e2f to your computer and use it in GitHub Desktop.
join() method of thread
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
| import threading | |
| import logging | |
| from time import sleep | |
| logging.basicConfig(level=logging.DEBUG, | |
| format='(%(threadName)-10s) %(message)s', | |
| ) | |
| def thread01(): | |
| logging.debug('Starting') | |
| sleep(5) | |
| logging.debug('Exiting') | |
| def thread02(t=None): | |
| logging.debug('Starting') | |
| if t is not None: | |
| logging.debug('Waiting for %s', t) | |
| t.join() | |
| logging.debug('Exiting') | |
| t1 = threading.Thread(name='thread01', target=thread01) | |
| t2 = threading.Thread(name='thread02', target=thread02, kwargs={'t': t1}) | |
| t1.start() | |
| t2.start() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
inspired by multithreading - what is the use of join() in python threading - Stack Overflow