mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-06 13:30:41 +02:00
client: replaces __del__ with __exit__ method to properly define ctx manager
This commit is contained in:
parent
7b786be892
commit
18df9e288a
@ -3,6 +3,7 @@ import logging
|
|||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
from types import TracebackType
|
||||||
from typing import TYPE_CHECKING, Any, TypedDict, cast
|
from typing import TYPE_CHECKING, Any, TypedDict, cast
|
||||||
|
|
||||||
import socketio # type: ignore
|
import socketio # type: ignore
|
||||||
@ -109,10 +110,14 @@ class Client:
|
|||||||
self.connect(block_until_connected=block_until_connected)
|
self.connect(block_until_connected=block_until_connected)
|
||||||
|
|
||||||
def __enter__(self) -> Self:
|
def __enter__(self) -> Self:
|
||||||
self.connect(block_until_connected=True)
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __del__(self) -> None:
|
def __exit__(
|
||||||
|
self,
|
||||||
|
exc_type: type[BaseException] | None,
|
||||||
|
exc_val: BaseException | None,
|
||||||
|
exc_tb: TracebackType | None,
|
||||||
|
) -> None:
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
|
||||||
def connect(self, block_until_connected: bool = True) -> None:
|
def connect(self, block_until_connected: bool = True) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user