r/learnpython • u/First-Ad6991 • 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
2
Upvotes
1
u/supercoach 2d ago
I assume you're importing queue, so if you are, you need to consider it a reserved word and not use it for a variable name. Change the name of the var to anything else and you should be fine.
2
u/Keinick_Mariazinha 1d ago
youre naming your local variable `queue` which shadows the imported `queue` module. just rename the variable to `q` or `work_queue` and it'll fix it