[Tutor] RE: Simple Thread Program not working (Newbie: Python)
karthik Guru
karthikg@aztec.soft.net
Sat, 10 Nov 2001 18:21:20 +0530
sorry got the bug. My __init__() declaration was the problem!
-----Original Message-----
From: karthik Guru [mailto:karthikg@aztec.soft.net]
Sent: Saturday, November 10, 2001 5:50 PM
To: tutor@python.org
Subject: Simple Thread Program not working (Newbie: Python)
Importance: High
hello all,
Am not sure why am getting the errors at the specified place ( I have pasted
the error on those lines)
Can someone help.
---------------
import threading, time
class Test:
def __init__(self):
self.data = "start"
def change(self,data):
self.data = data
def __str__(self):
return self.data
def __repr__(self):
return self.data
class ChangeThread(threading.Thread):
def __init_(self,val,a):
self.ref = a
threading.Thread.__init__(None,self)
def run(self):
count = 1
while 1:
self.ref.change(s,count) # AttributeError: ChangeThread instance
has no attribute 'ref'
count+=1
time.sleep(1)
class WatchThread(threading.Thread):
def __init_(self,val,a):
self.ref = a
threading.Thread.__init__(None,self)
def run(self):
while 1:
print 'changed data : ' + self.ref.data # AttributeError:
#ChangeThread instance has no attribute 'ref'
time.sleep(3)
def execute():
print 'Start execute'
t = Test()
t1 = WatchThread(None,t)
t2 = WatchThread(None,t)
t3 = WatchThread(None,t)
t1.start()
t2.start()
t3.start()
time.sleep(2)
t4 = ChangeThread(None,t)
t4.start()
if __name__ == '__main__':
execute()
This is the trace:
Start execute
Exception in thread Thread-1:
Traceback (most recent call last):
File "d:\python21\lib\threading.py", line 378, in __bootstrap
self.run()
File "thread1.py", line 30, in run
print 'changed data : ' + self.ref.data
AttributeError: WatchThread instance has no attribute 'ref'
Exception in thread Thread-2:
Traceback (most recent call last):
File "d:\python21\lib\threading.py", line 378, in __bootstrap
self.run()
File "thread1.py", line 30, in run
print 'changed data : ' + self.ref.data
AttributeError: WatchThread instance has no attribute 'ref'
Exception in thread Thread-3:
Traceback (most recent call last):
File "d:\python21\lib\threading.py", line 378, in __bootstrap
self.run()
File "thread1.py", line 30, in run
print 'changed data : ' + self.ref.data
AttributeError: WatchThread instance has no attribute 'ref'
Exception in thread Thread-4:
Traceback (most recent call last):
File "d:\python21\lib\threading.py", line 378, in __bootstrap
self.run()
File "thread1.py", line 20, in run
self.ref.change(s,count)
AttributeError: ChangeThread instance has no attribute 'ref'
--
http://mail.python.org/mailman/listinfo/python-list