threading.Lock() not working through script
Did you happen to name your module (or another module in the working directory) threading.py
? It would get imported ahead of the built-in threading
, causing this exact problem.
Trying running:
print(threading.__file__)
in your module, I suspect you'll find it's not the Python built-in.
Related videos on Youtube
Dutchman
Updated on November 29, 2022Comments
-
Dutchman 12 months
I'm experimenting with the threading function in python 3 to get my own pingtesting app/log working, so im following a youtube tutorial
When I've launched a python 3 interpreter, and run:
>>> import threading >>> print_lock = threading.Lock()
It correctly returns
>>> print_lock <_thread.lock object at 0x042093C8>
But when I use that piece of code in a script and try to run it as
python scriptName.py
I get an error saying the attribute Lock() doesn't exist
AttributeError: 'module' object has no attribute 'Lock'
How is this possible? I've verified what threading.Lock() returns when running the python interpreter, why isn't it recognized when I try to run it in a script and how can I get this running?
-
leandronn about 10 yearsPosted it. Any help? Thanks!
-
unutbu almost 8 yearsYou may have a (personal) file name
threading.py
which is shadowing the standard module,threading
. See stackoverflow.com/q/25695412/190597. -
Dutchman almost 8 yearsIt took a little bit to figure out, but you're right.. my script was called threading.py, and once I changed it to something else, the script ran like it's supposed to. lesson learned: dont name your script after the module'. Thanks a bunch!
-
-
leandronn about 10 yearsThanks for your answers. I've tried redirecting to my static external IP address but nothing happened. Don't you have an example?
-
zwets about 10 years@leandronn Forget about the DNS servers, you don't need them, nor the gateways. You're overcomplicating things. If you've made sure your domain name points to one of your public IP addresses, then configure your incoming modem to do port forwarding of port 80 to 192.168.2.111 and you're done.
-
zwets about 10 years@leandronn This question asks pretty much the same as you do (I will mark your question as a duplicate): askubuntu.com/questions/69723/…
-
leandronn about 10 yearsI have no incoming modem. It's more than a simple test for my house. I think you misunderstood the problem.
-
leandronn about 10 yearsI'm sorry, but that question has nothing to do with mine. Please reconsider your mark.
-
leandronn about 10 yearsLast, what I'm trying to do here, is to reach a mailserver also. So this would be the begining of the whole story.