(self)
| 89 | main.ui_server.updateWebsocket() |
| 90 | |
| 91 | def startTor(self): |
| 92 | if sys.platform.startswith("win"): |
| 93 | try: |
| 94 | self.log.info("Starting Tor client %s..." % self.tor_exe) |
| 95 | tor_dir = os.path.dirname(self.tor_exe) |
| 96 | startupinfo = subprocess.STARTUPINFO() |
| 97 | startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW |
| 98 | cmd = r"%s -f torrc --defaults-torrc torrc-defaults --ignore-missing-torrc" % self.tor_exe |
| 99 | if config.tor_use_bridges: |
| 100 | cmd += " --UseBridges 1" |
| 101 | |
| 102 | self.tor_process = subprocess.Popen(cmd, cwd=tor_dir, close_fds=True, startupinfo=startupinfo) |
| 103 | for wait in range(1, 3): # Wait for startup |
| 104 | time.sleep(wait * 0.5) |
| 105 | self.enabled = True |
| 106 | if self.connect(): |
| 107 | if self.isSubprocessRunning(): |
| 108 | self.request("TAKEOWNERSHIP") # Shut down Tor client when controll connection closed |
| 109 | break |
| 110 | # Terminate on exit |
| 111 | atexit.register(self.stopTor) |
| 112 | except Exception as err: |
| 113 | self.log.error("Error starting Tor client: %s" % Debug.formatException(str(err))) |
| 114 | self.enabled = False |
| 115 | self.starting = False |
| 116 | self.event_started.set(False) |
| 117 | return False |
| 118 | |
| 119 | def isSubprocessRunning(self): |
| 120 | return self.tor_process and self.tor_process.pid and self.tor_process.poll() is None |
no test coverage detected