Make sure to shutdown tor client if we started it
This commit is contained in:
parent
a0451065a2
commit
13019941b3
1 changed files with 10 additions and 1 deletions
|
@ -98,6 +98,9 @@ class TorManager(object):
|
||||||
time.sleep(wait * 0.5)
|
time.sleep(wait * 0.5)
|
||||||
self.enabled = True
|
self.enabled = True
|
||||||
if self.connect():
|
if self.connect():
|
||||||
|
tor_started = self.tor_process.poll() is None
|
||||||
|
if tor_started:
|
||||||
|
self.request("TAKEOWNERSHIP") # Shut down Tor client when controll connection closed
|
||||||
break
|
break
|
||||||
# Terminate on exit
|
# Terminate on exit
|
||||||
atexit.register(self.stopTor)
|
atexit.register(self.stopTor)
|
||||||
|
@ -109,7 +112,13 @@ class TorManager(object):
|
||||||
def stopTor(self):
|
def stopTor(self):
|
||||||
self.log.debug("Stopping...")
|
self.log.debug("Stopping...")
|
||||||
try:
|
try:
|
||||||
self.tor_process.terminate()
|
tor_started = self.tor_process.poll() is None
|
||||||
|
if tor_started:
|
||||||
|
self.request("SIGNAL SHUTDOWN")
|
||||||
|
if sys.platform.startswith("win"):
|
||||||
|
subprocess.call(['taskkill', '/F', '/T', '/PID', str(self.tor_process.pid)]) # Also kill sub-processes
|
||||||
|
else:
|
||||||
|
self.tor_process.terminate()
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
self.log.error("Error stopping Tor: %s" % err)
|
self.log.error("Error stopping Tor: %s" % err)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue