[Twisted-Python] mutex in twisted?

Phil Mayers p.mayers at imperial.ac.uk
Tue Mar 11 07:49:03 EDT 2008

Gabriel Rossetti wrote:
> Gabriel Rossetti wrote:
>> Hello,
>> Is there some sort of mutex/semaphore code that can be used in 
>> twisted? I need to run an external subprocess from twisted when I get 
>> some data from a client and I'd like to make sure that while one 
>> client's data spawned the process to run, some other client will not 
>> do the same at the same time, thus my need for a mutex. Maybe there is 
>> another way to do this in a more twisted sort of way (pun not 
>> intended)? If so I'd love to hear how!
>> Thanks,
>> Gabriel
>> _______________________________________________
>> Twisted-Python mailing list
>> Twisted-Python at twistedmatrix.com
>> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
> Oh, I forgot to say, I use this for the process :
> subprocess.call(["festival", "--tts", filename])

You can't do that. The python "subprocess" module is blocking, and yuo 
will block the reactor and stop Twisted running.

> I'm not sure if it is useful for anyone, but I just saw that Twisted has 
> some sort of process code too, though it looks a bit complicated for my 
> needs.

You need to use it.

You can use:


...if you want to just run a simple command

As for mutex - since Twisted isn't multithreaded, you can just use a 
flag variable.

More information about the Twisted-Python mailing list