15

I'm trying to import the threading module, however, i just seem to get errors for no good reason. Here is my code:

import threading

class TheThread ( threading.Thread ):
    def run ( self ):
        print 'Insert some thread stuff here.'
        print 'I\'ll be executed...yeah....'
        print 'There\'s not much to it.'

TheThread.Start()

And the errors:

Traceback (most recent call last):
  File "threading.py", line 1, in <module>
    import threading
  File "C:\Users\Trent\Documents\Scripting\Python\Threading\threading.py", line
3, in <module>
    class TheThread ( threading.Thread ):
AttributeError: 'module' object has no attribute 'Thread'
Press any key to continue . . .

Python stats:

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win 32

2
  • 7
    Do you have file named "threading.py" in your current directory? If so, this would probably be the cause of there being no Thread attribute. Commented Nov 9, 2011 at 9:07
  • Remember to delete threading.pyc if you have run the code before Commented Apr 12, 2018 at 18:40

4 Answers 4

57

i think that all you need is just to rename the name of your working file, because your file name is the same as module name:

threading.py

or you have wrong threading.py file in your working directory

Sign up to request clarification or add additional context in comments.

3 Comments

I'm confused as to why this answer didn't exist when I left my comment above. Anyway, you beat me to it.
silly me not to noteice that the file was same name as module :/
Tyler, i answered, then temporary deleted answer to simulate this situation on my computer:)
4

First, you have to rename your own file: It is called threading.py and since it is in the Python Path it replaces the threading module of the standard Python library.

Second, you have to create an instance of your thread-class:

TheThread().start() # start with latter case

Comments

0

_thread.start_new_thread(func*)

1 Comment

this is the new syntax for python 3
0

I think you used threading name to your current working file.Change your file name with different name.It will work.It works for me too

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.