[python-uk] Tell us what you did with Python this year....
doug.winter at isotoma.com
Wed Dec 22 12:38:35 CET 2010
Reza Lotun wrote:
> # async friendly version of the above
> def get_foo_nicer(arg1, arg2):
> args = prepare_request()
> result = make_maybe_blocking_call()
> def post_process(result):
> The second version is exactly the same as the previous, but now it
> becomes much easier to make it async (rather, Twisted aware). The key
Nice idea making your synchronous code work like this too.
Have you considered using the @inlineCallbacks decorator instead? I bet
you could make that work too, you could write your own decorator that
uses inlineCallbacks or something synchronous, then the above becomes:
def get_foo(arg1, arg2):
args = prepare_request()
result = yield make_maybe_blocking_call()
finalValue = do_more_stuff(result)
Which can be a lot neater when you get stacks and stacks of callbacks.
Python's lack of a block construct otherwise makes that really unpleasant.
Telephone: +44 1904 567330, Mobile: +44 7879 423002
Switchboard: +44 1904 567349, Fax: +44 20 79006980
Post: Tower House, Fishergate, York, YO10 4UA, UK
Registered in England. Company No 5171172. VAT GB843570325.
Regd Office: 3&4 Park Court, Riccall Road, Escrick, York, YO19 6ED
More information about the python-uk