fix daemon for windows

This commit is contained in:
Tafelpoot 2014-11-20 11:52:57 +01:00
parent 5adb10e4d2
commit 75a0da8913
1 changed files with 9 additions and 4 deletions

View File

@ -36,8 +36,13 @@ DAEMON_PORT=8001
def do_start_daemon(config):
import subprocess
logfile = open(os.path.join(config.path, 'daemon.log'),'w')
p = subprocess.Popen(["python2",__file__], stderr=logfile, stdout=logfile, close_fds=True)
print_stderr("starting daemon (PID %d)"%p.pid)
if sys.platform == "win32":
p = subprocess.Popen(["python",__file__], stderr=logfile, stdout=logfile)
print_stderr("starting daemon (PID %d)"%p.pid)
else:
p = subprocess.Popen(["python2",__file__], stderr=logfile, stdout=logfile, close_fds=True)
print_stderr("starting daemon (PID %d)"%p.pid)
def get_daemon(config, start_daemon=True):
@ -47,7 +52,7 @@ def get_daemon(config, start_daemon=True):
while True:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('', daemon_port))
s.connect(('localhost', daemon_port))
if not daemon_started:
print_stderr("Connected to daemon on port %d"%daemon_port)
return s
@ -190,7 +195,7 @@ def daemon_loop(server):
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
daemon_port = server.config.get('daemon_port', DAEMON_PORT)
daemon_timeout = server.config.get('daemon_timeout', 5*60)
s.bind(('', daemon_port))
s.bind(('localhost', daemon_port))
s.listen(5)
s.settimeout(1)
t = time.time()