nova team mailing list archive
-
nova team
-
Mailing list archive
-
Message #00066
Re: How best to implement a synchronous interface method with an asynchronous implementation?
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?
>>> 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.
> 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)
?
> this is assuming of course the libvirt c bindings release the GIL.
True.
--
Soren Hansen
Ubuntu Developer
http://www.ubuntu.com/
Follow ups
References