The function that I want to run is part of a class, not a standalone function. There are several class member variables also.
Regards, Ashish Vyas -----Original Message----- From: python-list-bounces+ntb837=motorola....@python.org [mailto:python-list-bounces+ntb837=motorola....@python.org] On Behalf Of Mick Krippendorf Sent: Monday, October 12, 2009 10:52 PM To: python-list@python.org Subject: Re: deepcopy of class inherited from Thread VYAS ASHISH M-NTB837 schrieb: > I have an object which has a run() method. But I can call it only once. > Calling the start() again will give > > RuntimeError: thread already started > > So what is the way to do this? > > I thought of doing a deep copy of the object, as shallow copy will > also lead to the above error. > I tried this: > - deepcopy the object > - call start() for the object you got from deepcopy > - delete the object. > > Is there a simpler way to achieve this? Indeed, there is: def threaded(): """ do threaded stuff here """ Thread(target=threaded).start() Thread(target=threaded).start() Thread(target=threaded).start() Thread(target=threaded).start() Thread(target=threaded).start() Now threaded() runs five times. Python is not Java where one has to subclass from Thread (AFAIR the dark ages where I used to speak Javanese). Mick, -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list