nova team mailing list archive
Mailing list archive
Re: How best to implement a synchronous interface method with an asynchronous implementation?
On Tue, Aug 3, 2010 at 10:43 AM, Soren Hansen <soren@xxxxxxxxxx> wrote:
> On Tue, Aug 03, 2010 at 10:37:04AM -0400, Kapil Thangavelu wrote:
> >> Using standard Twisted, no. I doubt it's possible. You need threads
> >> or coroutines or something to pull that off and Twisted uses neither.
> > Well its possible, but its not useful, as it will still hang the
> > process.
> How can you block waiting for a deferred to fire?
Sorry i missed in the context that it was on a deferred. As you said, there
isn't a way to do that in twisted.
> >>> Perhaps we can clarify the Twisted vs Eventlet discussion: would
> >>> Eventlet solve this particular problem?
> >> The inlineCallbacks thing? Yes. The libvirt thing? Not as far as I
> >> know. eventlet has this patching mechanism, but as I understand it,
> >> it relies on the particular module using Python's socket module to
> >> work, which python-libvirt doesn't, AFAIK.
> > making the libvirt sync call into async for the purposes of twisted
> > should be easy enough..
> Sure. The question was about eventlet.
i think eventlet has the same functionality (defer call to thread).. ala
> > def threaded_invoke_sync_hang_api(on_result, args):
> > result = libvirt.get_info(args)
> > reactor.callFromThread(on_result, result)
> > def get_libvirt_info(*args):
> > d = Deferred()
> > reactor.deferToThread(threaded_invoke_sync_hang_api, args)
> > return d
> Why not just:
> def get_libvirt_info(*args):
> return reactor.deferToThread(libvirt.get_info, args)
doh.. yup. that's much better. i was looking at the signature of
reactor.callInThread which didn't have a return.