Skip to content

Commit

Permalink
deprecate await Client() in favour of async with Client()
Browse files Browse the repository at this point in the history
see also:

- dask#6785
- dask#6201
  • Loading branch information
graingert committed Aug 16, 2022
1 parent 3647cfe commit 4e83d3b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion distributed/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ class Client(SyncMethodMixin):

preloads: list[preloading.Preload]
__loop: IOLoop | None = None
__aentering = False

def __init__(
self,
Expand Down Expand Up @@ -1133,6 +1134,12 @@ def start(self, **kwargs):
sync(self.loop, self._start, **kwargs)

def __await__(self):
if not self.__aentering:
warnings.warn(
"await Client() is deprecated, use async with Client():",
DeprecationWarning,
stacklevel=2,
)
if hasattr(self, "_started"):
return self._started.__await__()
else:
Expand Down Expand Up @@ -1379,7 +1386,11 @@ def __enter__(self):
return self

async def __aenter__(self):
await self
self.__aentering = True
try:
await self
finally:
self.__aentering = False
return self

async def __aexit__(self, exc_type, exc_value, traceback):
Expand Down

0 comments on commit 4e83d3b

Please sign in to comment.