Hi Mark, > It sounds like you are after a named semaphore in the "Global\\" namespace. The semaphore count should work fine when your process terminates abnormally ...
Thanks for your help. I'm experimenting with the semaphore concept and I think its possible for my semaphore counts to fall out of sync in certain situations. In a perfect world, semaphores look like a great solution, but I may need to fall back to my idea of a collection of mutex's. Admittedly this is an awkward solution, but mutex's seem to be a very reliable way to determine whether a process is holding a resource or not, eg. they consistently get released when a process terminates abnormally. ----- Original message ----- From: "Mark Hammond" <skippy.hamm...@gmail.com> To: pyt...@bdurham.com Cc: "Tim Golden" <m...@timgolden.me.uk>, "zz Python Win32 Newsgroup" <python-win32@python.org> Date: Thu, 11 Mar 2010 12:52:43 +1100 Subject: Re: [python-win32] Technique to limit number of instances of our application under Terminal Server It sounds like you are after a named semaphore in the "Global\\" namespace. The semaphore count should work fine when your process terminates abnormally - but will not if it simply hangs - so something will need to terminate a hung process before the semaphore becomes available. HTH, Mark On 11/03/2010 8:16 AM, pyt...@bdurham.com wrote: > Hi Tim, > >> It's not quite clear whether you want something which you can build into the >> application itself > > Yes, since I control the source code, this is a feature I would like to > build into my applications. > >> ... in which case, the answer's probably Semaphores: >> http://msdn.microsoft.com/en-us/library/ms685129%28VS.85%29.aspx > > Thanks for that link. My understanding is that semaphores only to apply > to threads within a single running application? > > On the other hand, perhaps the term 'threads' applies to applications as > well? I say that because the term thread is used to describe mutex's > which I've used on a program vs. thread basis. > > Microsoft's description of Mutex's > http://msdn.microsoft.com/en-us/library/ms684266%28VS.85%29.aspx > > My research on semaphors also leads me to believe that if an application > incremented a semaphor and crashed without decrementing the semaphore, > then my semaphore count would be incorrect. Since the code in question > is being run in a test environment, the possibility of abnormal > terminations is higher than one would normally expect. Does this sound > accurate to you? > >> Obviously there are other approaches: you could write transient pid files in >> the Unix fashion, you could use Job objects to group your processes together >> in one job: > http://msdn.microsoft.com/en-us/library/ms684161%28VS.85%29.aspx > > What are your thoughts on using a pre-assigned list of mutexes. An > application would walk a list of named mutex's trying to lock one for > itself. If an application iterated through a list of mutex's without > securing one for itself, it would exit. > > The advantage of mutex's over semaphores would be that applications that > terminate abnormally would have their mutex released, while applications > using semaphors that terminated abnormally would leave their semaphore > with an incorrect count? > > The disadvantage of using mutex's vs. semaphores is that the time to > find a free mutex might be much slower than the time to simply increment > or decrement a semaphor. > > On the other hand, one of my colleagues claims that neither semphores or > mutuxes will be visible to other Terminal Service users. In other words, > all I will be able to do with semaphores and mutex's is to make sure a > SPECIFIC user doesn't run an application more than once. Put another > way, there may be no such thing as Global (that are visible across user > sessions) semaphores and mutex's. > > So I'm back to thinking about your PID file idea :) > > Regards, > Malcolm > _______________________________________________ > python-win32 mailing list > python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32