[PYTHON] queue
import logging
import queue
import threading
import time
logging.basicConfig(level=logging.DEBUG, format='%(threadName)s: %(message)s')
def worker1(queue):
logging.debug('start')
queue.put(100) #[100, 200]
time.sleep(5)
queue.put(200)
logging.debug('end')
def worker2(queue):
logging.debug('start')
logging.debug(queue.get())
logging.debug(queue.get()) #Value in queue(200)Will wait until
logging.debug('end')
if __name__ == '__main__':
queue = queue.Queue()
t1 = threading.Thread(target=worker1, args=(queue,))
t2 = threading.Thread(target=worker2, args=(queue,))
t1.start()
t2.start()
Thread-1: start
Thread-2: start
Thread-2: 100
Thread-1: end
Thread-2: 200
Thread-2: end