Question about threading

+2 Shlesh Tiwari · January 8, 2016
Hi all, 

I'm having some trouble with the threading code. I seemed to have written it like explained in the tutorial, but I'm still getting errors. Kindly help me out here. Here is the code.

import threading

class Firsttrial(threading.Thread):
def run(self):
for _ in range(5):
print threading.currentThread().getName(), '! Hello'

x = Firsttrial(name='Name 1')
y = Firsttrial(name='Name 2')

The error is:

Traceback (most recent call last):
  File "C:/Users/LENOVO/Documents/6.00.1xFile/", line 1, in <module>
    import threading
  File "C:\Users\LENOVO\Documents\6.00.1xFile\", line 3, in <module>
    class Firsttrial(threading.Thread):
AttributeError: 'module' object has no attribute 'Thread'

Process finished with exit code 1


Post a Reply


Oldest  Newest  Rating
+1 Sjoerd van den Belt · January 8, 2016
The file name that you are working in is the same as the module name "". This will make python think you are referring to this file when using "import threading".
Simply change your working file name and it should be solved.

Besides, try to put your code in a "code" block when creating a question, makes it easier to read :)
0 Shlesh Tiwari · January 8, 2016
Yeah, that worked. Thank you so much. I shall put the code in a code block next time. I also had another question regarding Bucky's web crawler assignment. Can you check that out too? 
Here is the link:

  • 1



This section is all about snakes! Just kidding.

Bucky Roberts Administrator