Tor subprocess check separate function

This commit is contained in:
shortcutme 2018-04-29 02:45:56 +02:00
parent 4fa43fdf60
commit d7c1c0d04c
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
1 changed files with 5 additions and 4 deletions

View File

@ -98,8 +98,7 @@ class TorManager(object):
time.sleep(wait * 0.5)
self.enabled = True
if self.connect():
tor_started = self.tor_process.poll() is None
if tor_started:
if self.isSubprocessRunning():
self.request("TAKEOWNERSHIP") # Shut down Tor client when controll connection closed
break
# Terminate on exit
@ -109,11 +108,13 @@ class TorManager(object):
self.enabled = False
return False
def isSubprocessRunning(self):
return self.tor_process and self.tor_process.pid and self.tor_process.poll() is None
def stopTor(self):
self.log.debug("Stopping...")
try:
tor_started = self.tor_process.poll() is None
if tor_started:
if self.isSubprocessRunning():
self.request("SIGNAL SHUTDOWN")
except Exception, err:
self.log.error("Error stopping Tor: %s" % err)