Bain Bain - 1 year ago 117
Python Question

Using Queue in python

I'm trying to run the following in Eclipse (using PyDev) and I keep getting error :

q = queue.Queue(maxsize=0)
NameError: global name 'queue' is not defined

I've checked the documentations and appears that is how its supposed to be placed. Am I missing something here? Is it how PyDev works? or missing something in the code? Thanks for all help.

from queue import *

def worker():
while True:
item = q.get()

def main():

q = queue.Queue(maxsize=0)
for i in range(num_worker_threads):
t = Thread(target=worker)
t.daemon = True

for item in source():

q.join() # block until all tasks are done


Eclipse SDK

Version: 3.8.1
Build id: M20120914-1540

and Python 3.3

Answer Source

You do

from queue import *

This imports all the classes from the queue module already. Change that line to

q = Queue(maxsize=0)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download