← Back to team overview

nova team mailing list archive

Re: How best to implement a synchronous interface method with an asynchronous implementation?

 

show details 4:08 PM (0 minutes ago)
I believe Twisted's maybeDefferred is for this purpose.  If you use that for
the calls into virt, each provider can used deferreds or not vor the various
methods.  We use it from api.py to call the endpoint methods

Vish

On Mon, Aug 2, 2010 at 1:19 PM, Justin Santa Barbara <justin@xxxxxxxxxxxx>wrote:

> I'm hacking on adding VirtualBox support (to allow native Mac development,
> more than as a serious production target).  This means adding another virt
> provider (I'm trying without libvirt for now, because libvirt VirtualBox
> support seems a little flaky, and I'm not sure about libvirt on the mac)
>  However one of the methods (get_info) is synchronous on the interface, but
> the VirtualBox implementation is asynchronous (it gets its results from
> spawning a process).  How do I handle this?
>
> A) Do I change the interface so that the method returns a deferred even in
> the providers that are synchronous?  If so, we should just have all
> interfaces return a deferred on all methods, so that the interface doesn't
> expose the implementation.  However, this would make everything messy...
>
> B) Should I type-check the result of the call and synchronously wait on
> it if it is deferred?  (And can anyone point me at some code that can do a
> sync-wait?)
>
> As an aside, and to borrow from the Wizard of Oz, "Twisted, I've a feeling
> we're not in Python any more".  Every method is preceded by
> @defer.inlineCallbacks, return x becomes returnValue(x), and there are
> yields scattered throughout the code based on whether the called method
> returns a deferred or not.  Perhaps we can clarify the Twisted vs Eventlet
> discussion: would Eventlet solve this particular problem?
>
> Justin
>
>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~nova
> Post to     : nova@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~nova
> More help   : https://help.launchpad.net/ListHelp
>
>

Follow ups

References