r/learnpython • • 2d ago

i got UnboundLocalError: local variable 'queue' referenced before assignment, how to fix please

def main(ips, users, passwords, ThreadNumber):

queue = queue.Queue(maxsize=20000)

for t in range(ThreadNumber):

try:

t = Apophis(queue)

t.daemon = True

t.start()

except Exception as e:

break

for passwd in passwords:

for user in users:

for host in ips:

queue.put((host, user, passwd))

queue.join()

0 Upvotes

2 comments sorted by

4

u/Temporary_Pie2733 2d ago

You define a local variable queue that immediately shadows the global variable referencing the module. Pick a different name for the local variable. 

1

u/Sehzat_Davoyan 2d ago

same thing happens all the time with time and json too, super easy trap to fall into