Skip to content

Instantly share code, notes, and snippets.

@modeyang
Created July 2, 2013 10:44
Show Gist options
  • Select an option

  • Save modeyang/5908360 to your computer and use it in GitHub Desktop.

Select an option

Save modeyang/5908360 to your computer and use it in GitHub Desktop.
github
#!/usr/bin/python
#coding=utf-8
import sys, os
import time
project_path = os.path.dirname(__file__)
project_path = os.path.join(project_path, '..')
sys.path.append(project_path)
import threading
from Queue import Queue, Empty as QueueEmpty
class MTWorker(threading.Thread):
"""
MTWorker
"""
def __init__(self, queue, processor=None):
threading.Thread.__init__(self)
self.task_queue = queue
self.processor = processor
def run(self):
while True:
try:
data = self.task_queue.get(block=False)
if self.processor is not None:
self.processor(data)
self.task_queue.task_done()
except QueueEmpty:
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment