Skip to content

Commit

Permalink
WIP: Removing make_current; quite cargo-culted
Browse files Browse the repository at this point in the history
  • Loading branch information
wence- committed Nov 2, 2022
1 parent 8d1c4df commit 05e4496
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 37 deletions.
4 changes: 1 addition & 3 deletions distributed/nanny.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,9 +866,7 @@ def _run(
if silence_logs:
logger.setLevel(silence_logs)

IOLoop.clear_instance()
loop = IOLoop()
loop.make_current()
loop = IOLoop.current()
worker = Worker(**worker_kwargs)

async def do_stop(timeout=5, executor_wait=True):
Expand Down
27 changes: 11 additions & 16 deletions distributed/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
map_varying,
nodebug,
popen,
pristine_loop,
randominc,
save_sys_modules,
slowadd,
Expand Down Expand Up @@ -2206,12 +2205,13 @@ async def test_multi_client(s, a, b):


def long_running_client_connection(address):
with pristine_loop():
async def run():
c = Client(address)
x = c.submit(lambda x: x + 1, 10)
x.result()
sleep(100)

asyncio.new_event_loop().run_until_complete(run())


@gen_cluster()
async def test_cleanup_after_broken_client_connection(s, a, b):
Expand Down Expand Up @@ -5538,23 +5538,18 @@ async def test_future_auto_inform(c, s, a, b):
await asyncio.sleep(0.01)


@pytest.mark.filterwarnings("ignore:There is no current event loop:DeprecationWarning")
@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning")
@pytest.mark.filterwarnings("ignore:clear_current is deprecated:DeprecationWarning")
def test_client_async_before_loop_starts(cleanup):
async def close():
async def run():
loop = IOLoop.current()
client = Client(asynchronous=True, loop=loop)
assert client.asynchronous
assert isinstance(client.close(), NoOpAwaitable)
async with client:
pass

with pristine_loop() as loop:
with pytest.warns(
DeprecationWarning,
match=r"Constructing LoopRunner\(loop=loop\) without a running loop is deprecated",
):
client = Client(asynchronous=True, loop=loop)
assert client.asynchronous
assert isinstance(client.close(), NoOpAwaitable)
loop.run_sync(close) # TODO: client.close() does not unset global client
loop = asyncio.new_event_loop()
loop.run_until_complete(run())
loop.close()


# FIXME shouldn't consistently fail on windows, may be an actual bug
Expand Down
18 changes: 0 additions & 18 deletions distributed/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,6 @@ async def run():
return


@contextmanager
def pristine_loop():
IOLoop.clear_instance()
IOLoop.clear_current()
loop = IOLoop()
loop.make_current()
assert IOLoop.current() is loop
try:
yield loop
finally:
try:
loop.close(all_fds=True)
except (KeyError, ValueError):
pass
IOLoop.clear_instance()
IOLoop.clear_current()


original_config = copy.deepcopy(dask.config.config)


Expand Down

0 comments on commit 05e4496

Please sign in to comment.