Fix race condition

This commit is contained in:
Otto Winter 2019-01-19 15:26:29 +01:00
parent d37602cfdd
commit 9bcb7f1cce
No known key found for this signature in database
GPG Key ID: DB66C0BE6013F97E
1 changed files with 5 additions and 1 deletions

View File

@ -600,10 +600,14 @@ class APIClient:
raise APIConnectionError("Already connected!")
connected = False
stopped = False
async def _on_stop():
if self._connection is None:
nonlocal stopped
if stopped:
return
stopped = True
self._connection = None
if connected and on_stop is not None:
await on_stop()