Fix exception ignored warnings and invalid state #935

This commit is contained in:
Lonami Exo 2018-08-04 15:05:22 +02:00
parent d0c566bbdb
commit a688c8a4ce
2 changed files with 9 additions and 2 deletions

View File

@ -151,7 +151,14 @@ class TcpClient:
loop=self._loop
)
for r in running:
r.cancel()
if not r.cancelled():
if r.done():
# Retrieve exception to avoid "not retrieved" errors
r.exception()
# Cancel the future despite its state
r.cancel()
if not self.is_connected:
raise self.SocketClosed()
if not done:

View File

@ -167,7 +167,7 @@ class MTProtoSender:
self._recv_loop_handle.cancel()
__log__.info('Disconnection from {} complete!'.format(self._ip))
if self._disconnected:
if self._disconnected and not self._disconnected.done():
if error:
self._disconnected.set_exception(error)
else: