python proxy checker ,change to threaded version

r0g aioe.org at technicalbloke.com
Mon Dec 7 18:49:04 EST 2009


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.



More information about the Python-list mailing list