Newbie Thread question continues...

Matthew matthewmNOSPAM at ihug.co.nz
Mon Dec 11 14:36:31 EST 2000


Thanks for the replies to my first post.

The python docs state

There are two ways to specify the activity: by passing a
callable object to the constructor, or by overriding the run() method in a subclass. No other methods (except for the constructor) should be
overridden in a subclass. In other words, only override the __init__() and run() methods of this class. 

Okay, so you can have stuff like

class Dog(threading.Thread):
	def run(self):
		do stuff

dog = Dog()
dog.start()

I've got that far. However, it's generally been my understanding to NOT
subclass Thread unless it directly builds on Thread's functionality. So a
few more questions:-

a) Howto in Python do something like Java's:- 
new Thread(new Dog()).start() where Dog doesn't subclass Thread, but
rather wraps a Dog instance inside it's own thread.

b) In Thread, can someone please explain the use of 'target',
'args','kargs', and preferable give
a quck example to use the Thread constructor as in:

Thread (group=None, target=None, name=None, args=(), kwargs={}) 
       This constructor should always be called with keyword arguments. Arguments are: 

       group Should be None; reserved for future extension when a ThreadGroup class is implemented. 

       target Callable object to be invoked by the run() method. Defaults to None, meaning nothing is called. 

       args Argument tuple for the target invocation. Defaults to (). 

       kwargs Keyword argument dictionary for the target invocation. Defaults to {}.


THANK-YOU. matthew



More information about the Python-list mailing list