From: kaliko Date: Sun, 23 Oct 2011 12:23:56 +0000 (+0200) Subject: some clean up in error handling. X-Git-Tag: 0.4~1 X-Git-Url: https://git.kaliko.me/?a=commitdiff_plain;h=96583cae101396a40e36dc34820e0f5f7ba4c6e6;p=python-daemon.git some clean up in error handling. --- diff --git a/src/daemon.py b/src/daemon.py index 2251f18..c364efd 100644 --- a/src/daemon.py +++ b/src/daemon.py @@ -20,7 +20,7 @@ class Daemon(object): Usage: subclass the Daemon class and override the run() method """ - version = "0.3" + version = "0.4" def __init__(self, pidfile, stdin='/dev/null', @@ -84,10 +84,8 @@ class Daemon(object): try: os.umask(self.umask) file(self.pidfile, 'w').write('%s\n' % pid) - #except IOError, wpid_err: except Exception, wpid_err: - sys.stderr.write(u'Error trying to write pid file to %s: %s\n' % - (unicode(self.pidfile, 'utf-8'), wpid_err)) + sys.stderr.write(u'Error trying to write pid file: %s\n' % wpid_err) sys.exit(1) os.umask(0) atexit.register(self.delpid) @@ -100,7 +98,11 @@ class Daemon(object): sys.exit(1) def delpid(self): - os.unlink(self.pidfile) + try: + os.unlink(self.pidfile) + except OSError as err: + message = 'Error trying to remove PID file: %s\n' + sys.stderr.write(message % err) def start(self): """ @@ -159,7 +161,7 @@ class Daemon(object): sys.stderr.write(message % self.pidfile) os.remove(self.pidfile) else: - print str(err) + sys.stderr.write(err.strerror) sys.exit(1) def restart(self):