windows code to detect if a process is still alive
John Arbash Meinel
john at arbash-meinel.com
Thu Apr 14 07:28:51 UTC 2011
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 04/14/2011 09:22 AM, Voelker, Bernhard 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?
>
> Have a nice day,
> Berny
It locks it from being renamed, but any # of processes can open a file
for writing concurrently.
You can get into OS level locking, but that opens up a host of new bugs.
Plus, it doesn't work remotely. (You can't ask for an OS lock over ftp
or sftp, for example.)
Also, it is really hard to be a little bit cooperative with OS level
locks. In bzr, most Read locks are no-ops that just enable caching,
since our data structures on disk can be added to without violating
consistency of the older data. OS level locks won't actually let you
have a Read lock and a Write lock. You also tend to get bad error messages.
For example, if I hold an OS lock, and your process wants to access it,
we get a "Cannot do that", but we don't get the information about what
user holds the lock, how long they've held it, etc. (hence the 'info' file.)
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEUEARECAAYFAk2mojMACgkQJdeBCYSNAAOl9wCcDbc5oNJ/i7aV5OhIHTech2+e
kT8AmKHvXTYjNwsURfkhpGA3tnWjmXc=
=1w0D
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list