Skip to content

Instantly share code, notes, and snippets.

@mmitou
Created February 18, 2016 02:55
Show Gist options
  • Select an option

  • Save mmitou/6da6ff03e7ebe02cc120 to your computer and use it in GitHub Desktop.

Select an option

Save mmitou/6da6ff03e7ebe02cc120 to your computer and use it in GitHub Desktop.
# -*- 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