Created
February 18, 2016 02:55
-
-
Save mmitou/6da6ff03e7ebe02cc120 to your computer and use it in GitHub Desktop.
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
| # -*- coding:utf-8 -*- | |
| from __future__ import print_function, division, unicode_literals | |
| import threading | |
| import Queue | |
| import time | |
| class Worker(threading.Thread): | |
| def __init__(self, queue): | |
| self.queue = queue | |
| threading.Thread.__init__(self) | |
| def run(self): | |
| print('run!') | |
| while(True): | |
| data = self.queue.get() | |
| print(data) | |
| if data == 'bye!': | |
| break | |
| def stop(self): | |
| self.queue.put('bye!') | |
| self.join() | |
| if __name__ == '__main__': | |
| q = Queue.Queue() | |
| worker = Worker(q) | |
| worker.setDaemon(True) | |
| worker.start() | |
| for i in range(0, 10): | |
| q.put(i) | |
| time.sleep(1) | |
| worker.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment