Skip to content

Instantly share code, notes, and snippets.

@cdpath
Created March 6, 2018 10:28
Show Gist options
  • Select an option

  • Save cdpath/e972521539ad1aedc26b10bf72df6e2f to your computer and use it in GitHub Desktop.

Select an option

Save cdpath/e972521539ad1aedc26b10bf72df6e2f to your computer and use it in GitHub Desktop.
join() method of thread
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()
@cdpath
Copy link
Author

cdpath commented Mar 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment