Threading question

Kent Johnson kent37 at tds.net
Fri Apr 22 14:55:45 EDT 2005


codecraig wrote:
> If i have a class such as
> 
> class Foo:
>     def doSomething(self, cmd, cmd2, callback):
>         cmd = <translate command>
>         results = <..do some possibly long task..>
>         callback(results)
> 
> What I am looking to do is have that "long task" done in a separate
> thread...how can I do this?

import threading and add this method to class Foo:

   def doSomethingThreaded(self, cmd, cmd2, callback):
     threading.Thread(target=self.doSomething, args=(cmd, cmd2, callback)).start()


You also might be interested in this recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/84317

Kent



More information about the Python-list mailing list