[Twisted-Python] Blocking on deferreds during unit tests (e.g. deferredResult)

Christopher Armstrong radeex at gmail.com
Tue May 10 19:50:57 EDT 2005


On 5/10/05, Kevin Dangoor <dangoor at gmail.com> wrote:
> I understand that... The Twisted Enterprise database api, if I
> understand correctly, uses the Twisted threadpool to wrap otherwise
> blocking database calls behind new calls that return deferreds.
> sqlobject, on the otherhand, was written in a traditional
> (non-callback) style.
> 
> My thought was to use gthreadless to create an interface between
> Twisted Enterprise (ADBAPI?) and sqlobject. For sqlobject, it would
> look just like the blocking interface it was used to. But, it would be
> able to take advantage of the thread management already done by
> ADBAPI.


This won't work because gthreadless doesn't allow you to write
interfaces that look synchronous. It only lets *you* use asynchronous
interfaces in a synchronous-looking way. That is to say, your code
that wants to be synchronous-looking still isn't 100% transparent; you
need to call blockOn() around every Deferred you get. And a
gthreadless-function always returns a Deferred itself, so there's
really no way you could use the SQLObject code to talk to an
asynchronous backend.


-- 
  Twisted   |  Christopher Armstrong: International Man of Twistery
   Radix    |    -- http://radix.twistedmatrix.com
            |  Release Manager, Twisted Project
  \\\V///   |    -- http://twistedmatrix.com
   |o O|    |  Founding Member, Hobart Hacking Society
w----v----w-+    -- http://hackingsociety.org/chapters/hash




More information about the Twisted-Python mailing list