passing argumetns to threading.Thread
Peter Hansen
peter at engcorp.com
Sat Oct 4 23:23:06 EDT 2003
sashan wrote:
>
> I'm trying to pass arguments to my the run method of my class that
> inherits from threading.Thread.
>
> class Reader(threading.Thread):
> def __init__(self, conn):
> threading.Thread.__init__(self, None, None, None, (conn))
>
> def run(self,conn):
> while 1:
> data = conn.recv(1024)
> print data
You can't pass run() arguments.
You can, however, use instance variables since Reader is an object:
class Reader(threading.Thread):
def __init__(self, conn):
threading.Thread.__init__(self) # no need for extra args
self.conn = conn
def run(self):
while 1:
data = self.conn.recv(1024)
print data
-Peter
More information about the Python-list
mailing list