[Tutor] Watch and control access to an executable

Bill Burns billburns at pennswoods.net
Sat Apr 8 18:08:42 CEST 2006


[Bill]
>>>Desktop to the executable). The problem is, only *one* person at a time
>>>should run the program.
> 

[Snip some good advise about file problems (that I'll look in to)]

[André]
> However, there is a Cookbook solution that does, I believe, that what
> the original poster asked:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/67663
> 
> It is actually so short that I can even reproduce it below.
> =========
> from win32event import CreateMutex
> from win32api import GetLastError
> from winerror import ERROR_ALREADY_EXISTS
> from sys import exit
> 
> handle = CreateMutex ( None, 1, 'A unique mutex name' )
> 
> if GetLastError ( ) == ERROR_ALREADY_EXISTS:
> # take appropriate action if this is the second
> # instance of this script; for example,
>     print 'Oh! dear, I exist already.'
>     exit ( 1 )
> ============
> A detailed explanation (of a slightly modified version) can be found
> in the second edition of the Python Cookbook [Recipe 9.9].

André,

Thanks for the pointer to this recipe!

If I'm not mistaken (and I certainly could be) I believe this recipe is 
used to control instances of an already running *script*. While I'm 
trying to control a completely different executable (program) written by 
someone else.

Maybe I'm reading the recipe wrong?? I'll take a better look at it and 
see if it will work for my situation.

Thanks for the reply!!

Bill



More information about the Tutor mailing list