hello,
I've been working on threads and queues and I think I have it working well. The
problem seems to be that when I run a thread via the IDLE it crashes. if I
simply double click the file it appears to run ok. I'm not sure if I'm doing
something incorrectly or not. it seems pretty straight forward. my sample code
is listed below. I'm using Python 2.6.2, and I'm running on Microsoft Vista.
Any thoughts would be much appreciated. thanks!
Jeff
import threading
import Queue
import time, random
WORKERS = 2
class Worker(threading.Thread):
def __init__(self, queue):
self.__queue = queue
threading.Thread.__init__(self)
def run(self):
while 1:
item = self.__queue.get()
if item is None:
break # reached end of queue
# pretend we're doing something that takes 10-100 ms
time.sleep(random.randint(10, 100) / 100.0)
print "task", item, "finished"
#
# try it
queue = Queue.Queue(0)
for i in range(WORKERS):
print 'starting'
Worker(queue).start() # start a worker
for i in range(10):
print 'putting'
queue.put(i)
for i in range(WORKERS):
print 'putting None'
queue.put(None) # add end-of-queue markers
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor