[Twisted-Python] Perspective Broker with blocking, non-thread-safe C api?

glyph at divmod.com glyph at divmod.com
Wed Jul 11 11:38:14 EDT 2007

On 03:25 pm, ellisonbg.net at gmail.com wrote:
>The reason is that is you call a blocking C api in the thread, the
>Python interpreter will not be able to switch threads until the
>blocking C calls....unless the C code releases the Global Interpreter
>Lock.  Thus you have two choices:
(1 and 2 snipped)
>The way we usually handle this is to make a separate process that
>manages a queue of commands to be executed on the server.  Clients
>then connect to this manager, which in turns submits them to the
>actual PB server at the appropriate time.  This is a pain, but it
>works extremely well.

That sounds like a viable "third choice", and I have a fourth ;).

Have the PB server itself spawn a subprocess (or multiple subprocesses!) 
dedicated to this particular API.  Then simply block in that (those) 
subprocess(es), and return Deferreds from your PB methods that wait for 
those requests to complete.

That way the PB server remains self-contained and you don't add the 
administrative overhead of setting up a separate server.

More information about the Twisted-Python mailing list