Last active
August 29, 2015 14:05
-
-
Save kounoike/d471069af56948d09b75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import os | |
import sys | |
import Queue | |
import threading | |
import logging | |
import time | |
num_workers = 3 | |
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(threadName)s %(message)s") | |
q = Queue.Queue() | |
def worker(): | |
try: | |
while True: | |
item = q.get() | |
logging.info("get item: %d", item) | |
q.task_done() | |
except Exception: | |
logging.error("caught exception", exc_info=True) | |
for i in range(num_workers): | |
t = threading.Thread(target=worker, name="t{0:d}".format(i)) | |
t.daemon = True | |
t.start() | |
for item in [1, 4, 3, 5, 2, 7, 8, 6, 9]: | |
time.sleep(item) | |
q.put(item) | |
q.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment