windows code to detect if a process is still alive

Martin Pool mbp at canonical.com
Thu Apr 14 07:39:26 UTC 2011


On 14 April 2011 17:22, Voelker, Bernhard
<bernhard.voelker at siemens-enterprise.com> wrote:
> Martin Pool wrote:
>
>> For detection of stale lock files, I want to detect whether a given
>> process id on the local machine still corresponds to a live process.
>> On unix, kill(pid, 0) will do this.  What's the best way to do this
>> from inside Python on Windows?
>
> I don't know too much about Python, but as (C code) fopen("file", "w") locks
> a file for others automatically on Windows, doesn't Python just use
> that internally for locking?

Good question.  The files we're talking about are not necessarily
local.  Someone might open a repository over sftp and lose their
connection, and then want to do something else to the same branch from
the same client machine.  In fact, this is a good case of when stale
locks can be left behind, because if the connection drops over sftp
there is no possibility for the client to release its lock.

Martin



More information about the bazaar mailing list