Browse Source

simplify get_daemon

283
ThomasV 9 years ago
parent
commit
7641137ecc
  1. 34
      electrum

34
electrum

@ -369,29 +369,17 @@ class NetworkServer(util.DaemonThread):
print_error("Daemon exiting") print_error("Daemon exiting")
def get_daemon(config):
def get_daemon(config, start_daemon):
daemon_socket = os.path.join(config.path, DAEMON_SOCKET) daemon_socket = os.path.join(config.path, DAEMON_SOCKET)
daemon_started = False try:
while True: s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try: s.connect(daemon_socket)
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) return s
s.connect(daemon_socket) except socket.error:
return s return False
except socket.error: except:
if not start_daemon: # do not use daemon if AF_UNIX is not available (windows)
return False return False
elif not daemon_started:
daemon_started = True
else:
time.sleep(0.1)
except:
# do not use daemon if AF_UNIX is not available (windows)
return False
@ -472,7 +460,7 @@ if __name__ == '__main__':
config_options['password'] = password config_options['password'] = password
# check if daemon is running # check if daemon is running
s = get_daemon(config, False) s = get_daemon(config)
if s: if s:
p = util.SocketPipe(s) p = util.SocketPipe(s)
p.set_timeout(1000000) p.set_timeout(1000000)

Loading…
Cancel
Save