Detect if specific Python.app instance is already running

Laura Creighton lac at openend.se
Mon Jun 8 14:21:41 EDT 2015


I needed to do something like this once.  What I needed was a way to
send a process a signal, and have it then spit out a huge amount
of stats about how long it had been running, how many page faults
it had suffered, and, goodness, I forget all the information that
was needed.  Lots.  So I just wrapped the code in something that
waited to see if it got the special signal from hell, and, when it
did spit out the information.

It was not pretty, but that is the sort of thing you do when somebody
comes by after you have written something with some new requirements
that basically mean you would have to rewrite the thing.

Of course, sending odd signals to random processes in your proc table,
asking them to identify themselves, runs the risk that the process
isn't set up to receive signals it doesn't expect gracefully, and may
fall over dead when you do so.  So I am not sure I can actually
recommend this technique, but it is one way to skin this particular cat.

Laura




More information about the Python-list mailing list