send shutdown signal to tor

This commit is contained in:
j 2016-02-07 19:22:56 +05:30
parent 2bad1b30d2
commit 8070b3b8a9
1 changed files with 13 additions and 3 deletions

View File

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