Skip to content

Instantly share code, notes, and snippets.

@CUXIDUMDUM
Created May 24, 2015 18:51
Show Gist options
  • Save CUXIDUMDUM/2c3b4c173e3ae0b819c6 to your computer and use it in GitHub Desktop.
Save CUXIDUMDUM/2c3b4c173e3ae0b819c6 to your computer and use it in GitHub Desktop.
threads
!/usr/bin/python
import Queue
import threading
import time
class workerthread(threading.Thread):
def __init__(self,queue):
threading.Thread.__init__(self)
self.queue=queue
def run(self):
print 'In Worker Class'
while True:
counter=self.queue.get()
print 'Going to Sleep'
time.sleep(counter)
print ' I am up!'
self.queue.task_done()
queue=Queue.Queue()
for i in range(10):
worker=workerthread(queue)
print 'Going to Thread!'
worker.daemon=True #prog will block after All Done, if not daemon
worker.start()
for j in range(10):
queue.put(j)
queue.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment