[python-win32] Technique to limit number of instances of our application under Terminal Server

Tim Golden mail at timgolden.me.uk
Fri Mar 12 15:31:54 CET 2010


On 12/03/2010 14:21, python at bdurham.com wrote:
> Tim,
>
> Thank you for your example code and ideas!!
>
> I think my earlier experiments with semaphores may be the result of my
> poor code vs. your approach :)
>
> I'm going to put aside my pool of mutex's idea and experiment with your
> sample code.

Good luck. Be aware of Christopher Nilsson's point that while
the Mutex will be released if the holding process crashes hard,
the Semaphore will not release its token. (Haven't tried this
myself; I'm assuming he's had experience or has read the docs
more carefully than me).

The bind-to-a-socket approach is a good general-purpose solution.
(It can be used on any socket-based system where binding semantics
disallow simultaneous connections).

Greg Ewing's "control server" is the kind of thing you'd be doing
for license control, eg, and has the advantage he points out about
detecting dead session. But it has the overhead of a control process.
Which may or may not be an issue for you.

TJG


More information about the python-win32 mailing list