Detecting second instance of a program in NT!
Roger Burnham
roger.burnham at gte.net
Wed May 12 19:29:06 EDT 1999
On Wed, 12 May 1999 12:04:21 -0500, "SunitJoshi" <SunitJoshi at email.msn.com> wrote:
> I was wondering if it's possible to note a more than one instance of an
>application being opened, using python in NT env. Also is it possible to
>time the start & end of an instance.
>
Sunit,
I use
On startup:
import win32event, win32ui, winerror
self.singleInstanceMutex = win32event.CreateMutex(None, 1, self.name)
lastErr = win32api.GetLastError()
if lastErr == winerror.ERROR_ALREADY_EXISTS:
msg = '''
You are already running a copy of:
%s
Only one at a time allowed!
''' % self.name
win32ui.MessageBox(msg, 'Can only run one instance')
raise SystemExit
and on exit:
win32event.ReleaseMutex(self.singleInstanceMutex)
Cheers,
Roger Burnham
Cambridge Research & Instrumentation
rburnham at cri-inc.com
http://www.cri-inc.com/
http://starship.python.net/crew/roger/
PGP Key: http://www.nai.com/default_pgp.asp
PGP Fingerprint: 5372 729A 9557 5F36 177F 084A 6C64 BE27 0BC4 CF2D
More information about the Python-list
mailing list