[Twisted-Python] Synchronous Code Fishbowl

glyph at divmod.com glyph at divmod.com
Sun May 28 23:41:30 MDT 2006



On Sat, 27 May 2006 18:48:59 -0700, Ed Suominen <general at eepatents.com> wrote:
>The dialogue copied below shows yet another example of the frustrations
>that arise when trying to bridge the chasm between Twisted and the
>synchronous rest of the world.
>
>This latest episode inspired the idea of a synchronous code fishbowl
>that offers well-behaved Twisted code a deferToQueue() method for
>running badly-behaved blocking code.
>
>See http://foss.eepatents.com/sAsync/browser/branches/syncbridge.py
>
>Comments?

syncbridge looks like an interesting module.  I've often wanted to do something similar, to have a "one right way" for integrating with non-async-clean legacy code which also doesn't necessarily support threaded concurrency either.

However, I notice that nothing sets up the 'shutdown' method to be called on reactor shutdown automatically; this is a very tricky area, since mismanaged thread-pool shutdown can lock a process up hard as it's exiting.

Also, have you considered just using a twisted.python.threadpool of maximum size 1, rather than callInThread?  The main reason I didn't document that as the aforementioned "one right way" was because of the associated shutdown issues.  The major advantage of callInThread is that the reactor's own threadpool is definitely initialized and shut down at predictable points.

HTH,

-glyph




More information about the Twisted-Python mailing list