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): > do_stuff(result) > do_more_stuff(result) > 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: @cleverInlineCallbacks def get_foo(arg1, arg2): args = prepare_request() result = yield make_maybe_blocking_call() do_stuff(result) finalValue = do_more_stuff(result) defer.returnValue(finalValue) 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. Cheers, Doug. -- 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 _______________________________________________ python-uk mailing list python-uk@python.org http://mail.python.org/mailman/listinfo/python-uk