Skip to content

Commit

Permalink
Consistent pidfile, clearer errors for ConsensoProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny O'Brien authored and Danny O'Brien committed Aug 17, 2012
1 parent 9076da4 commit 0c7094f
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions consenso/bot/client.py
Expand Up @@ -13,7 +13,6 @@

import subprocess
import os.path
import tempfile
import os
import signal

Expand All @@ -23,14 +22,13 @@
class ConsensoProcess(object):

furlfile = os.path.join(consenso.directories.foolscap_dir, "root.furl")
default_pidfile = os.path.join(consenso.directories.foolscap_dir, "pid")

def __init__(self, pidfile=None, logfile=None):
self.pid = None
self._furl = None
if not pidfile:
(f, pidfile) = tempfile.NamedTemporaryFile(
prefix="consensobot", suffix="pid", delete=False)
f.close()
pidfile = self.default_pidfile
if not logfile:
logfile = os.path.join(consenso.directories.log_dir, 'client.log')
self._pidfile = pidfile
Expand All @@ -43,7 +41,7 @@ def start(self):
command.append("--logfile={}".format(self._logfile))
if os.path.exists(self.furlfile):
os.unlink(self.furlfile)
subprocess.call(command, stderr=subprocess.STDOUT)
subprocess.check_call(command, stderr=subprocess.STDOUT)
pid = 0
furl = ""
while (pid == 0 or furl == ""): # FIXME shouldn't buzz around a loop, should use select
Expand All @@ -62,8 +60,9 @@ def furl(self):
if not self._furl:
try:
furl = file(self.furlfile, "r").read()
except IOError:
furl = None
except IOError as e:
print e
print "Have you remembered to start() the ConsensoProcess?"
self._furl = furl
return self._furl

Expand Down

0 comments on commit 0c7094f

Please sign in to comment.