translating "create Semaphore" to Linux

GHUM haraldarminmassa at gmail.com
Fri Aug 29 13:28:45 CEST 2008


hello,

in my application I am using

hSem = win32event.CreateSemaphore (None, 1,
1,"stringincludinginterfaceandport")
rt=win32event.WaitForSingleObject (hSem, 0)
if rt != win32event.WAIT_TIMEOUT:
   really_do_start_my_app()
else:
   print "application allready running"

to make sure that only ONE instance of the application is running at a
time. (as it implements a local webserver, that is necessary. Two
webservers listening on one port is bad)

Now I am going to make this application run on Linux. How can I get
similiar behaviour on Linux?

I know of the .pid files that get written by some server processes ...
BUT they do not get cleaned up on unclean shutdown of the application.

is there some better method?

Or some module which wraps the details of .pid-files quite nicely?
(like "trying to remove to check if other instance is still
running...., failing properly on missing write privs etc.)

best wishes,

Harald



More information about the Python-list mailing list