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')
x.start()
y.start()

The error is:

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

Process finished with exit code 1

Thanks.

Post a Reply

Replies

Oldest  Newest  Rating
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: https://www.thenewboston.com/forum/topic.php?id=10970

 Thanks. 
+1 Sjoerd van den Belt · January 8, 2016
The file name that you are working in is the same as the module name "threading.py". 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 :)
  • 1

Python

103,455 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator