Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > help mutex

Reply
Thread Tools

help mutex

 
 
Didier FRAISSE
Guest
Posts: n/a
 
      10-23-2003
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


 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      10-23-2003
> 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 ??


I think you should not try to create, but to actually *lock* the mutex. Then
the other scripts are blocked, until the first one executes. Then the next
one gets access.

I have no w32-api here, but at least thats what I remember from my old days
writing com-objects in C++....

Diez


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between mutex.mutex and threading.Lock sven Python 2 12-04-2009 11:30 PM
problem mutex-thread "Unlocking mutex owned by another thread ???" NaeiKinDus C++ 3 04-15-2007 09:35 PM
problem mutex-thread "Unlocking mutex owned by another thread ???" NaeiKinDus C++ 1 04-14-2007 07:40 PM
Need help on Mutex =?iso-8859-1?B?YUKj?= ASP .Net 2 03-15-2005 03:59 PM
What permissions for Mutex to be shared? William LaMartin ASP .Net 0 10-16-2003 09:39 PM



Advertisments