Terry J. Reedy tjre...@udel.edu added the comment:
Avoiding an exception for a very rare use case is an inadequate reason to add a
new function. Requests to add someone's favorite short, specialized, and
easy-to-write function are a common feature of python-list.
--
nosy: +tjreedy
New submission from Patricio Mariano Molina patriciomol...@gmail.com:
I couldn't find anything like os.pid_exists() in Python 2.5/2.6, neither
in bugs.python.org (this *could* be a dupe)
Do we have something like that?
Right now I'm doing this:
try:
os.kill(int(pid), 0)
return True
Jean-Paul Calderone exar...@divmod.com added the comment:
This is quite a microoptimization. Why do you think you need to avoid
the exception here?
--
nosy: +exarkun
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6554
Jean-Paul Calderone exar...@divmod.com added the comment:
For what it's worth, here are some timings from my system. First,
os.kill without raising an exception:
exar...@boson:~$ python -m timeit -s 'import os; pid = os.getpid()' '
os.kill(pid, 0)
'
100 loops, best of 3: 0.413 usec per
Patricio Mariano Molina patriciomol...@gmail.com added the comment:
Hey Jean-Paul, thanks for the quick reply!
You're right, but I wasn't thinking too much about optimization: I think
it would be useful to have that simple function, returning True or False.
I use to search for active PIDs *a
Jean-Paul Calderone exar...@divmod.com added the comment:
It might be better to pick a better (but probably platform-specific) API
for such a use-case. os.kill has a problem with false positives (on
Linux it will tell you a process exists even when it doesn't). Looking
in /proc/ or using a
Patricio Mariano Molina patriciomol...@gmail.com added the comment:
Sounds good. And what do you think about os.pid_exists() using /proc/ or
a Windows API?
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6554
Jean-Paul Calderone exar...@divmod.com added the comment:
The os module is mostly for wrappers around native platform APIs. So at
the very least, I don't think such an API belongs there. It would fit
in to a general process-related module, perhaps.
--
Martin v. Löwis mar...@v.loewis.de added the comment:
I'd love to do the same without catching an exception (they're
expensive!)
Why do you say that? I don't believe that exceptions are expensive
(e.g. compared to the system call)
--
nosy: +loewis
title: Do we have something like