python proxy checker ,change to threaded version

r0g aioe.org at technicalbloke.com
Tue Dec 8 09:48:47 EST 2009


Lie Ryan wrote:
> On 12/8/2009 8:43 AM, Rhodri James wrote:
>>>
>>> def run(self):
>>> result = func(*func_args) # matching run_in_thread param names
>>> callback(result, *callback_args)
>> Neat, but I think you mean
>>
>> if callback is not None:
>> callback(result, *callback_args)
>>
>> for that last line.
> 
> how about:
> import threading
> 
> def run_in_thread( func, func_args=[], callback=lambda r,*a: None,
> callback_args=[] ):
>     class MyThread ( threading.Thread ):
>         def run ( self ):
>             result = func(*func_args)
>             callback(result, *callback_args)
>     MyThread().start()
> 
> 
> (and for me, I'd )


Cool, that's a neat trick I'd never have thought of. I think the 2 line
alternative might be a little more pythonic though, in terms of
readability & simplicity...

if callback:
    callback(result, *callback_args)

That could be because I'm not terribly au fait with the whole lambda
calculus thing though. What say those who are comfortable with it?
Obvious or oblique?

Roger.



More information about the Python-list mailing list