import logging
import threading
import time
logging.basicConfig(level=logging.DEBUG, format='%(threadName)s: %(message)s')
def worker1(barrier):
r = barrier.wait()
logging.debug('num={}'.format(r))
while True:
logging.debug('start')
time.sleep(2)
logging.debug('end')
def worker2(barrier):
r = barrier.wait()
logging.debug('num={}'.format(r))
while True:
logging.debug('start')
time.sleep(2)
logging.debug('end')
if __name__ == '__main__':
barrier = threading.Barrier(2)
t1 = threading.Thread(target=worker1, args=(barrier,))
t2 = threading.Thread(target=worker2, args=(barrier,))
t1.start()
t2.start()
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme