Ah, I think I understand. You can probably solve this by having a Future and making the callback set the Future's result. Perhaps you should also run the 3rd party code in a thread.
On Wed, May 21, 2014 at 3:27 PM, Phil Schaf <[email protected]>wrote: > Am Donnerstag, 22. Mai 2014 00:04:58 UTC+2 schrieb Guido van Rossum: > > Can you show the code you are referring to? I cannot figure out what your >> question is from your description. >> > Sure! > > #i can’t change thisclass ThirdPartyJob: > def __init__(self, cb): > self.callback = cb > > def do_things(self): > for _ in range(200): > message = churn() > callback(message) > #i can change everything hereclass MyServerProtocol: > def __init__(self): > self.task = None > > @coroutine > def onMessage(self, msg): > if msg == 'cancel': > self.task.cancel() > else: > self.task = async(self.do_task(msg)) > yield from self.task > self.task = None > > @coroutine > def do_task(self, msg): > def cb(m): > #i want to yield do_task from here if possible > print(m) > job = ThirdPartyJob(cb) > job.do_things() > > so the server gets messages, and calls the 3rd party code unless the > message is to cancel the last order, in which case this should get done, > and then the server should wait for the next message. > > this would work if, instead of job.do_things(), i would use a loop and > yield inside of it. but that’s impossible: > > this is a simplified version. > > in reality, the third party job does things that can’t be reimplemented > easily, and the loop sits pretty deep, so no reimplementing of everything > down to the loop. > > -- --Guido van Rossum (python.org/~guido)
