Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion kasa/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ async def _query(self, request: str, retry_count: int, timeout: int) -> Dict:

def __del__(self) -> None:
if self.writer and self.loop and self.loop.is_running():
self.writer.close()
# Since __del__ will be called when python does
# garbage collection is can happen in the event loop thread
# or in another thread so we need to make sure the call to
# close is called safely with call_soon_threadsafe
self.loop.call_soon_threadsafe(self.writer.close)
self._reset()

@staticmethod
Expand Down