Created
May 24, 2015 18:51
-
-
Save CUXIDUMDUM/2c3b4c173e3ae0b819c6 to your computer and use it in GitHub Desktop.
threads
This file contains 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 | |
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