Revision 560cbec1 lib/utils.py
b/lib/utils.py | ||
---|---|---|
2342 | 2342 |
""" |
2343 | 2343 |
def _helper(pid, signal_, wait): |
2344 | 2344 |
"""Simple helper to encapsulate the kill/waitpid sequence""" |
2345 |
os.kill(pid, signal_) |
|
2346 |
if wait: |
|
2345 |
if IgnoreProcessNotFound(os.kill, pid, signal_) and wait: |
|
2347 | 2346 |
try: |
2348 | 2347 |
os.waitpid(pid, os.WNOHANG) |
2349 | 2348 |
except OSError: |
... | ... | |
3122 | 3121 |
return bool(exitcode) |
3123 | 3122 |
|
3124 | 3123 |
|
3124 |
def IgnoreProcessNotFound(fn, *args, **kwargs): |
|
3125 |
"""Ignores ESRCH when calling a process-related function. |
|
3126 |
|
|
3127 |
ESRCH is raised when a process is not found. |
|
3128 |
|
|
3129 |
@rtype: bool |
|
3130 |
@return: Whether process was found |
|
3131 |
|
|
3132 |
""" |
|
3133 |
try: |
|
3134 |
fn(*args, **kwargs) |
|
3135 |
except EnvironmentError, err: |
|
3136 |
# Ignore ESRCH |
|
3137 |
if err.errno == errno.ESRCH: |
|
3138 |
return False |
|
3139 |
raise |
|
3140 |
|
|
3141 |
return True |
|
3142 |
|
|
3143 |
|
|
3125 | 3144 |
def IgnoreSignals(fn, *args, **kwargs): |
3126 | 3145 |
"""Tries to call a function ignoring failures due to EINTR. |
3127 | 3146 |
|
Also available in: Unified diff