[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()) #Valeur en file d'attente(200)Attendra jusqu'à
    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

Recommended Posts

queue
File d'attente Python #stack
À propos de la file d'attente
File d'attente ALDS1_3_B langage C
Traitement des requêtes en Python