| 324 | self.thread.start() |
| 325 | |
| 326 | def stop(self): |
| 327 | self.set_running(False) |
| 328 | # connect to self to end run loop |
| 329 | s = socket.socket(self.conf.af) |
| 330 | s.connect(self.conf.addr) |
| 331 | s.close() |
| 332 | self.thread.join() |
| 333 | # if there are active handlers, close them |
| 334 | with self._handlers_lock: |
| 335 | items = list(self._handlers) |
| 336 | for i, item in enumerate(items): |
| 337 | if item is None: |
| 338 | continue |
| 339 | thread, conn = item |
| 340 | # check if thread is still active |
| 341 | if not try_join_daemon_thread(thread, timeout=0): |
| 342 | conn.wakeup() |
| 343 | if try_join_daemon_thread(thread, timeout=2): |
| 344 | logger.debug(f"Stop(): Handler {i} thread joined") |
| 345 | else: |
| 346 | logger.warning(f"Stop(): Handler thread {i} didn't finish after force close") |
| 347 | |
| 348 | def start_socks5_server(destinations_factory): |
| 349 | config = Socks5Configuration() |