[Twisted-Python] Getting a list of services and/or plugins are currently running

Glyph Lefkowitz glyph at twistedmatrix.com
Mon Oct 18 15:51:18 EDT 2010

On Oct 18, 2010, at 3:10 PM, Elizabeth Liao wrote:

> Sorry about that.  I just started using twisted so I'll try to be more specific.
> We have 2 different twisted plugins that uses shared code.   Each of these plugins is run as a  TCPClient on separate machines.
> What would like to do is to somehow identify what twisted services/plugins are running because different things happen depending on what plugin is currently in use.  We are running on Linux wanted to see if there was an easy way of doing that using the twisted libraries.  I suppose one solution is to get a list of processes running and parse that but I would rather not do that.
> Thanks.
> Liz

Sorry, but there is no easy API to do this using Twisted.  It's not really clear to me how such an API could be meaningful, either, given that any Twisted plugin could easily invoke any arbitrary python code that it wants to, including other Twisted plugins.  But if you have a detailed specification for how it might work, please feel free to file a ticket.

One way you could deal with this would be to have a dedicated UNIX socket at a well-known path for your particular application (e.g. /tmp/.your-app/global-socket), and connect to that socket to identify the current system's role.  This requires a little more work, but has the advantage that if you go with an extensible protocol such as AMP, you can extend this communication mechanism to allow arbitrarily detailed interrogation depending on your needs in the future.

If you wanted to go with the 'listing processes' route (it is definitely simpler), you don't have to parse it yourself.  Something like this with the 'psi' module (<http://pypi.python.org/pypi/PSI>) might do what you want:

>>> from psi.process import ProcessTable
>>> pt = ProcessTable()
>>> for p in pt.values():
...   if 'twistd your-app' in p.command:
...     print p.pid

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20101018/b341ebca/attachment.htm 

More information about the Twisted-Python mailing list