OS independent way to check if a python app is running?
Dan Sommers
somm1105 at bellsouth.net
Mon Dec 14 22:07:04 EST 2009
On Mon, 14 Dec 2009 14:14:05 -0500, python wrote:
> Is there an os independent way to check if a python app is running?
>
> Goal: I have a server program based on cherrypy that I only want to have
> running once. If a system administrator accidentally attempts to run
> this program more than once, I would like the 2nd instance of the
> program to detect that its already running and exit.
Maybe I'm missing something, but the locking mechanism already exists:
at some point, your server program has to bind to an IP port to listen
for incoming request, and any respectable OS won't let two programs bind
to the same port at the same time. So if binding to the input port
works, then there *can't* be another instance of the program running
(multiple configuration files notwithstanding, but then you'd need a
second process anyway).
I guess I am assuming that "a server program based on cherrypy" takes its
input from an IP port, but that seems safe enough given the nature of
cherrypy.
Dan
More information about the Python-list
mailing list