restart tor daemon if its no longer running
This commit is contained in:
parent
ac3dd595cf
commit
ea40e64b9c
1 changed files with 12 additions and 7 deletions
19
oml/tor.py
19
oml/tor.py
|
@ -2,6 +2,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import time
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import distutils
|
import distutils
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class TorDaemon(Thread):
|
class TorDaemon(Thread):
|
||||||
installing = False
|
installing = False
|
||||||
|
running = True
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._status = []
|
self._status = []
|
||||||
|
@ -69,14 +71,17 @@ DirReqStatistics 0
|
||||||
tor = get_tor()
|
tor = get_tor()
|
||||||
if tor:
|
if tor:
|
||||||
cmd = [tor, '--defaults-torrc', defaults, '-f', torrc]
|
cmd = [tor, '--defaults-torrc', defaults, '-f', torrc]
|
||||||
self.p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1,
|
while self.running:
|
||||||
universal_newlines=True, close_fds=True, start_new_session=True)
|
self.p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1,
|
||||||
for line in self.p.stdout:
|
universal_newlines=True, close_fds=True, start_new_session=True)
|
||||||
self._status.append(line)
|
for line in self.p.stdout:
|
||||||
logger.debug(line)
|
self._status.append(line)
|
||||||
|
logger.debug(line)
|
||||||
|
time.sleep(0.5)
|
||||||
self.p = None
|
self.p = None
|
||||||
|
|
||||||
def shutdown(self):
|
def kill(self):
|
||||||
|
self.running = False
|
||||||
if self.p:
|
if self.p:
|
||||||
self.p.kill()
|
self.p.kill()
|
||||||
|
|
||||||
|
@ -154,7 +159,7 @@ class Tor(object):
|
||||||
#self.controller.remove_event_listener(self.connection_change)
|
#self.controller.remove_event_listener(self.connection_change)
|
||||||
self.controller.close()
|
self.controller.close()
|
||||||
if self.daemon:
|
if self.daemon:
|
||||||
self.daemon.shutdown()
|
self.daemon.kill()
|
||||||
except:
|
except:
|
||||||
logger.debug('shutdown exception', exc_info=True)
|
logger.debug('shutdown exception', exc_info=True)
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue