When I read some code,I think the usage of Event is not necessary,is it right?
# start server
while True:
# accept a request here
queue.put(info)
event.set() # notify all the threads?
# pass queue and event here to a Thread constructor
other place there are more than 10 threads running,
# inside a Thread class
def __init__(self, queue, event):
threading.Thread.__init__(self)
self.queue, self.event = queue, event
def run(self):
while True:
self.event.wait() # <- block here, I think this can be removed
info = self.queue.get() # <- block here again, only one thread can get job to do?
# do something
self.queue.task_done()
self.event.clear() #
eventis unnecessary. Furthermore, it seems as if event is global, which is probably not a good idea either, if it is to be used, event should be stored as an instance variable of the thread class. – Joel Cornett Jul 17 '12 at 1:49