← Back to team overview

nova team mailing list archive

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


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

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?


Follow ups