mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-03-31 07:14:14 +03:00
Join all threads when calling .disconnect() (fix #252)
This commit is contained in:
parent
f984aae391
commit
6f1c05633e
|
@ -271,18 +271,16 @@ class TelegramBareClient:
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
"""Disconnects from the Telegram server
|
"""Disconnects from the Telegram server
|
||||||
and stops all the spawned threads"""
|
and stops all the spawned threads"""
|
||||||
self._user_connected = False
|
self._user_connected = False # This will stop recv_thread's loop
|
||||||
self._recv_thread = None
|
|
||||||
|
|
||||||
# Stop the workers from the background thread
|
|
||||||
self.updates.stop_workers()
|
self.updates.stop_workers()
|
||||||
|
|
||||||
# This will trigger a "ConnectionResetError", for subsequent calls
|
# This will trigger a "ConnectionResetError" on the recv_thread,
|
||||||
# to read or send (from another thread) and usually, the background
|
# which won't attempt reconnecting as ._user_connected is False.
|
||||||
# thread would try restarting the connection but since the
|
|
||||||
# ._recv_thread = None, it knows it doesn't have to.
|
|
||||||
self._sender.disconnect()
|
self._sender.disconnect()
|
||||||
|
|
||||||
|
if self._recv_thread:
|
||||||
|
self._recv_thread.join()
|
||||||
|
|
||||||
# TODO Shall we clear the _exported_sessions, or may be reused?
|
# TODO Shall we clear the _exported_sessions, or may be reused?
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user