send shutdown signal to tor

This commit is contained in:
j 2016-02-07 19:22:56 +05:30
parent 2bad1b30d2
commit 8070b3b8a9

View file

@ -9,6 +9,7 @@ import zipfile
import ox import ox
import stem import stem
from stem import Signal
from stem.control import Controller from stem.control import Controller
from Crypto.PublicKey import RSA from Crypto.PublicKey import RSA
import settings import settings
@ -83,8 +84,15 @@ DirReqStatistics 0
cmd += self.geoip(tor) cmd += self.geoip(tor)
cwd = os.path.dirname(tor) cwd = os.path.dirname(tor)
while self.running: while self.running:
self.p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1, if sys.platform == 'win32':
universal_newlines=True, start_new_session=True, env=env, cwd=cwd) startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
self.p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1,
universal_newlines=True, start_new_session=True, env=env, cwd=cwd, startupinfo=startupinfo)
else:
self.p = subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1,
universal_newlines=True, start_new_session=True, env=env, cwd=cwd)
for line in self.p.stdout: for line in self.p.stdout:
self._status.append(line) self._status.append(line)
logger.debug(line) logger.debug(line)
@ -171,12 +179,14 @@ class Tor(object):
logger.debug('unknonw change %s', status) logger.debug('unknonw change %s', status)
def event_listener(self, event): def event_listener(self, event):
print('EVENT', event) logger.debug('EVENT', event)
def shutdown(self): def shutdown(self):
self._shutdown = True self._shutdown = True
try: try:
self.depublish() self.depublish()
if self.daemon and self.controller:
self.controller.signal(Signal.SHUTDOWN)
if self.controller: if self.controller:
#self.controller.remove_event_listener(self.connection_change) #self.controller.remove_event_listener(self.connection_change)
self.controller.close() self.controller.close()