threading.Lock() not working through script

1,531

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.

Share:
1,531

Related videos on Youtube

Dutchman
Author by

Dutchman

Updated on November 29, 2022

Comments

  • Dutchman
    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
      leandronn about 10 years
      Posted it. Any help? Thanks!
    • unutbu
      unutbu almost 8 years
      You may have a (personal) file name threading.py which is shadowing the standard module, threading. See stackoverflow.com/q/25695412/190597.
    • Dutchman
      Dutchman almost 8 years
      It 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
    leandronn about 10 years
    Thanks for your answers. I've tried redirecting to my static external IP address but nothing happened. Don't you have an example?
  • zwets
    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
    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
    leandronn about 10 years
    I have no incoming modem. It's more than a simple test for my house. I think you misunderstood the problem.
  • leandronn
    leandronn about 10 years
    I'm sorry, but that question has nothing to do with mine. Please reconsider your mark.
  • leandronn
    leandronn about 10 years
    Last, what I'm trying to do here, is to reach a mailserver also. So this would be the begining of the whole story.