Error catching in Process

This commit is contained in:
Mathieu Comandon 2015-03-05 04:16:10 +01:00
parent dabd331d8f
commit 7afe720b50

View file

@ -1,10 +1,18 @@
import os
import signal
from lutris.util.log import logger
class InvalidPid(Exception):
pass
class Process(object):
def __init__(self, pid, parent=None):
self.pid = pid
try:
self.pid = int(pid)
except ValueError:
raise InvalidPid("'%s' is not a valid pid" % pid)
self.children = []
self.parent = None
self.get_children()
@ -81,4 +89,7 @@ class Process(object):
return os.readlink(cwd_path)
def kill(self):
os.kill(self.pid, signal.SIGKILL)
try:
os.kill(self.pid, signal.SIGKILL)
except OSError:
logger.error("Could not kill process %s", self.pid)