[issue6554] Do we have something like os.pid_exists()?

2010-07-08 Thread Terry J. Reedy
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

[issue6554] Do we have something like os.pid_exists()?

2009-07-23 Thread Patricio Mariano Molina
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

[issue6554] Do we have something like os.pid_exists()?

2009-07-23 Thread Jean-Paul Calderone
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

[issue6554] Do we have something like os.pid_exists()?

2009-07-23 Thread Jean-Paul Calderone
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

[issue6554] Do we have something like os.pid_exists()?

2009-07-23 Thread Patricio Mariano Molina
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

[issue6554] Do we have something like os.pid_exists()?

2009-07-23 Thread Jean-Paul Calderone
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

[issue6554] Do we have something like os.pid_exists()?

2009-07-23 Thread Patricio Mariano Molina
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

[issue6554] Do we have something like os.pid_exists()?

2009-07-23 Thread Jean-Paul Calderone
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. --

[issue6554] Do we have something like os.pid_exists()?

2009-07-23 Thread Martin v . Löwis
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