I have the following program, and nothing else, python 3.3. When I run it. I get
NameError: name 'threading' is not defined
I googled but none of the answers given explain my situation. any clues? Thanks!
#!/usr/bin/python
import Utilities
import os
import sys
import getopt
import time
from queue import Queue
from threading import Thread
_db_lock=threading.Lock()
I also tried
_db_lock=threading.Lock
You must import threading. Add the following to the beginning of your file:
import threading
The error originates from the line:
_db_lock=threading.Lock()
That's because you've used from threading import Thread
, but you've never actually introduced threading
in to the local namespace. So far there's only Thread
(even though technically the import is there, it's just not in the namespace, you cannot use it).
If for some reason you wish to keep threading
from 'polluting' your namespace, import the Lock
in the same manner as you've imported Thread
, like so:
from threading import Thread, Lock
_db_lock = Lock()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With