translating "create Semaphore" to Linux

Tim Golden mail at timgolden.me.uk
Fri Aug 29 08:33:22 EDT 2008


GHUM wrote:
> 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. 


Running a serious risk of teaching my grandmother, but...

... why use a Semaphore rather than a Mutex? Or why not
simply use the bound socket as its own mutex? I know
Windows won't allow you to rebind the same socket to the
same addr/port in two different processes (unless perhaps
you play some trickery with the socket options).

TJG



More information about the Python-list mailing list