Untitled

 avatar
unknown
plain_text
a year ago
756 B
2
Indexable
from threading import Thread, Condition
import logging
from time import sleep

def worker(condition: Condition):
    logging.debug('Worker ready to work')
    with condition:
        condition.wait()
        logging.debug('Worker started to work')

def chief(condition: Condition):
    logging.debug('Im the boss')
    with condition:
        logging.debug('Im sending guys to work')
        condition.notify_all()

logging.basicConfig(level=logging.DEBUG, format='%(threadName)s %(message)s')
cond = Condition()

our_chief = Thread(target=chief, args=(cond,))
worker1 = Thread(target=worker, args=(cond,))
worker2 = Thread(target=worker, args=(cond,))

worker1.start()
worker2.start()
our_chief.start()

logging.debug('The end')
Leave a Comment