Message90852
For what it's worth, here are some timings from my system. First,
os.kill without raising an exception:
exarkun@boson:~$ python -m timeit -s 'import os; pid = os.getpid()' '
os.kill(pid, 0)
'
1000000 loops, best of 3: 0.413 usec per loop
exarkun@boson:~$
Next, os.kill without raising an exception, but with exception handling:
exarkun@boson:~$ python -m timeit -s 'import os; pid = os.getpid()' '
> try:
> os.kill(pid, 0)
> except OSError, e:
> pass
> '
1000000 loops, best of 3: 0.42 usec per loop
Finally, os.kill with exception handling and raising an exception:
exarkun@boson:~$ python -m timeit -s 'import os; pid = os.getpid()' '
try:
os.kill(pid + 1, 0)
except OSError, e:
pass
'
100000 loops, best of 3: 2.58 usec per loop
The slowest case is almost 7x slower than the fastest case. However,
this is only triggered when os.kill raises an exception (ie, if the pid
does exist, it's still fast). Plus, this "slow" case still only takes
two and a half microseconds. That's pretty fast. |
|
Date |
User |
Action |
Args |
2009-07-23 18:35:02 | exarkun | set | recipients:
+ exarkun, pmolina |
2009-07-23 18:35:02 | exarkun | set | messageid: <1248374102.09.0.57824528345.issue6554@psf.upfronthosting.co.za> |
2009-07-23 18:35:00 | exarkun | link | issue6554 messages |
2009-07-23 18:35:00 | exarkun | create | |
|