Terry Reedy wrote:
> r0g wrote:
> 
>> The trick to threads is to create a subclass of threading.Thread, define
>> the 'run' function and call the 'start()' method. I find threading quite
>> generally useful so I created this simple generic function for running
>> things in threads...
> 
> Great idea. Thanks for posting this.
> 
>> def run_in_thread( func, func_args=[], callback=None, callback_args=[] ):
<snipped cumbersome older version>


Okay, so here's the more concise version for posterity / future googlers...

import threading

def run_in_thread( func, func_args=[], callback=None, callback_args=[] ):
    class MyThread ( threading.Thread ):
        def run ( self ):
            result = func(*func_args)
            if callback:
                callback(result, *callback_args)
    MyThread().start()


Roger.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to