D
Didier FRAISSE
i want to be sure that only one instance of my script is running at the same
time
i try this little script
#---------------------------------------------------------------------------
# -*- coding: cp1252 -*-
from win32event import CreateMutex
from win32event import ReleaseMutex
from win32api import GetLastError
from winerror import ERROR_ALREADY_EXISTS
from time import sleep
mutex = None
attendre = True
while attendre:
mutex = CreateMutex ( None, 1, 'monmutexbienamoi' )
if (GetLastError ( ) == ERROR_ALREADY_EXISTS):
print 'another instance is running, i'm waiting'
sleep(10)
else:
attendre = False
print 'no instance, i'm running'
for i in range(10000):
print 'i'm working...'
# release the mutex
print 'release mutex %s. another instance could run' %mutex
ReleaseMutex( mutex )
#--------------------------------------------------------------------------
but it doesn't work when i launch multiple instance of my script.
the first one is running without problem.
The other one are waiting and are never released.
where is the trap ??
Didier
time
i try this little script
#---------------------------------------------------------------------------
# -*- coding: cp1252 -*-
from win32event import CreateMutex
from win32event import ReleaseMutex
from win32api import GetLastError
from winerror import ERROR_ALREADY_EXISTS
from time import sleep
mutex = None
attendre = True
while attendre:
mutex = CreateMutex ( None, 1, 'monmutexbienamoi' )
if (GetLastError ( ) == ERROR_ALREADY_EXISTS):
print 'another instance is running, i'm waiting'
sleep(10)
else:
attendre = False
print 'no instance, i'm running'
for i in range(10000):
print 'i'm working...'
# release the mutex
print 'release mutex %s. another instance could run' %mutex
ReleaseMutex( mutex )
#--------------------------------------------------------------------------
but it doesn't work when i launch multiple instance of my script.
the first one is running without problem.
The other one are waiting and are never released.
where is the trap ??
Didier