Created
July 2, 2013 10:44
-
-
Save modeyang/5908360 to your computer and use it in GitHub Desktop.
github
This file contains hidden or 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
| #!/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