From 773f61790392b25d9f5f5e5dd07765dbd88e7064 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Thu, 13 Oct 2022 10:49:18 +0100 Subject: [PATCH 1/8] Filter implicit deprecation warnings from tornado as well tornado 6.2 deprecates functionality that relies on deprecated asyncio calls (get_event_loop and friends); a few tests still use a pattern of implicitly creating a new loop (and test that appropriate deprecation warnings are uttered), so just catch these new tornado warnings for now, until the functionality is removed in distributed. --- distributed/deploy/tests/test_adaptive.py | 1 + distributed/deploy/tests/test_spec_cluster.py | 1 + distributed/tests/test_client.py | 4 ++++ distributed/tests/test_client_loop.py | 2 ++ distributed/tests/test_utils.py | 2 ++ 5 files changed, 10 insertions(+) diff --git a/distributed/deploy/tests/test_adaptive.py b/distributed/deploy/tests/test_adaptive.py index 31dcd7b4459..36b3198d8b5 100644 --- a/distributed/deploy/tests/test_adaptive.py +++ b/distributed/deploy/tests/test_adaptive.py @@ -281,6 +281,7 @@ async def test_no_more_workers_than_tasks(): @pytest.mark.filterwarnings("ignore:There is no current event loop:DeprecationWarning") +@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") def test_basic_no_loop(cleanup): loop = None try: diff --git a/distributed/deploy/tests/test_spec_cluster.py b/distributed/deploy/tests/test_spec_cluster.py index 31b95e28026..e0e7301fcf8 100644 --- a/distributed/deploy/tests/test_spec_cluster.py +++ b/distributed/deploy/tests/test_spec_cluster.py @@ -83,6 +83,7 @@ def test_spec_sync(loop): @pytest.mark.filterwarnings("ignore:There is no current event loop:DeprecationWarning") +@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") def test_loop_started_in_constructor(cleanup): # test that SpecCluster.__init__ starts a loop in another thread cluster = SpecCluster(worker_spec, scheduler=scheduler, loop=None) diff --git a/distributed/tests/test_client.py b/distributed/tests/test_client.py index c0d5b716220..56abd05268c 100644 --- a/distributed/tests/test_client.py +++ b/distributed/tests/test_client.py @@ -2873,6 +2873,7 @@ async def test_startup_close_startup(s, a, b): @pytest.mark.filterwarnings("ignore:There is no current event loop:DeprecationWarning") +@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") def test_startup_close_startup_sync(loop): with cluster() as (s, [a, b]): with Client(s["address"], loop=loop) as c: @@ -5597,6 +5598,8 @@ async def test_future_auto_inform(c, s, a, b): @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 with client: @@ -6914,6 +6917,7 @@ async def test_workers_collection_restriction(c, s, a, b): @pytest.mark.filterwarnings("ignore:There is no current event loop:DeprecationWarning") +@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") @gen_cluster(client=True, nthreads=[("127.0.0.1", 1)]) async def test_get_client_functions_spawn_clusters(c, s, a): # see gh4565 diff --git a/distributed/tests/test_client_loop.py b/distributed/tests/test_client_loop.py index 35bb3a7e861..9d8316cdd09 100644 --- a/distributed/tests/test_client_loop.py +++ b/distributed/tests/test_client_loop.py @@ -30,6 +30,7 @@ def _check_cluster_and_client_loop(loop): # Test if Client stops LoopRunner on close. @pytest.mark.filterwarnings("ignore:There is no current event loop:DeprecationWarning") +@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") def test_close_loop_sync_start_new_loop(cleanup): with _check_loop_runner(): _check_cluster_and_client_loop(loop=None) @@ -37,6 +38,7 @@ def test_close_loop_sync_start_new_loop(cleanup): # Test if Client stops LoopRunner on close. @pytest.mark.filterwarnings("ignore:There is no current event loop:DeprecationWarning") +@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") def test_close_loop_sync_use_running_loop(cleanup): with _check_loop_runner(): # Start own loop or use current thread's one. diff --git a/distributed/tests/test_utils.py b/distributed/tests/test_utils.py index 853ba578f11..b2dae76fdb2 100644 --- a/distributed/tests/test_utils.py +++ b/distributed/tests/test_utils.py @@ -405,6 +405,7 @@ def assert_not_running(loop): @pytest.mark.filterwarnings("ignore:There is no current event loop:DeprecationWarning") +@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") def test_loop_runner(loop_in_thread): # Implicit loop loop = IOLoop() @@ -488,6 +489,7 @@ def test_loop_runner(loop_in_thread): @pytest.mark.filterwarnings("ignore:There is no current event loop:DeprecationWarning") +@pytest.mark.filterwarnings("ignore:make_current is deprecated:DeprecationWarning") def test_two_loop_runners(loop_in_thread): # Loop runners tied to the same loop should cooperate From 4f69d8de4470dabc26c907d0537469c434fbd845 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Thu, 13 Oct 2022 10:58:29 +0100 Subject: [PATCH 2/8] Update tornado pinnings to allow 6.2 --- continuous_integration/environment-3.10.yaml | 2 +- continuous_integration/environment-3.8.yaml | 2 +- continuous_integration/environment-3.9.yaml | 2 +- continuous_integration/recipes/distributed/meta.yaml | 2 +- requirements.txt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/continuous_integration/environment-3.10.yaml b/continuous_integration/environment-3.10.yaml index ab5a2c91655..004d21fa67b 100644 --- a/continuous_integration/environment-3.10.yaml +++ b/continuous_integration/environment-3.10.yaml @@ -39,7 +39,7 @@ dependencies: - sortedcollections - tblib - toolz - - tornado<6.2 + - tornado=6.2 - zict # overridden by git tip below - zstandard >=0.9.0 - pip: diff --git a/continuous_integration/environment-3.8.yaml b/continuous_integration/environment-3.8.yaml index 083a0722626..fc2dbe38e89 100644 --- a/continuous_integration/environment-3.8.yaml +++ b/continuous_integration/environment-3.8.yaml @@ -42,7 +42,7 @@ dependencies: - sortedcollections - tblib - toolz - - tornado<6.2 + - tornado - zict - zstandard >=0.9.0 - pip: diff --git a/continuous_integration/environment-3.9.yaml b/continuous_integration/environment-3.9.yaml index 77887b6bf1b..de834619aae 100644 --- a/continuous_integration/environment-3.9.yaml +++ b/continuous_integration/environment-3.9.yaml @@ -45,7 +45,7 @@ dependencies: - tblib - toolz - torchvision # Only tested here - - tornado<6.2 + - tornado - zict - zstandard >=0.9.0 - pip: diff --git a/continuous_integration/recipes/distributed/meta.yaml b/continuous_integration/recipes/distributed/meta.yaml index e305d5d6f62..8cf137aadb4 100644 --- a/continuous_integration/recipes/distributed/meta.yaml +++ b/continuous_integration/recipes/distributed/meta.yaml @@ -42,7 +42,7 @@ requirements: - sortedcontainers !=2.0.0,!=2.0.1 - tblib >=1.6.0 - toolz >=0.8.2 - - tornado >=6.0.3,<6.2 + - tornado >=6.0.3 - urllib3 - zict >=0.1.3 run_constrained: diff --git a/requirements.txt b/requirements.txt index f6b6c8f9caf..e28e37408ee 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,7 @@ psutil >= 5.0 sortedcontainers !=2.0.0, !=2.0.1 tblib >= 1.6.0 toolz >= 0.8.2 -tornado >= 6.0.3, <6.2 +tornado >= 6.0.3 urllib3 zict >= 0.1.3 pyyaml From 6288fcf47ce26923201e86df7cf5b92ac9945127 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Wed, 2 Nov 2022 11:20:45 +0000 Subject: [PATCH 3/8] Consistently require tornado>=6.2 everywhere --- continuous_integration/environment-3.10.yaml | 2 +- continuous_integration/environment-3.8.yaml | 2 +- continuous_integration/environment-3.9.yaml | 2 +- continuous_integration/recipes/distributed/meta.yaml | 2 +- requirements.txt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/continuous_integration/environment-3.10.yaml b/continuous_integration/environment-3.10.yaml index 004d21fa67b..be9939b81c6 100644 --- a/continuous_integration/environment-3.10.yaml +++ b/continuous_integration/environment-3.10.yaml @@ -39,7 +39,7 @@ dependencies: - sortedcollections - tblib - toolz - - tornado=6.2 + - tornado >=6.2 - zict # overridden by git tip below - zstandard >=0.9.0 - pip: diff --git a/continuous_integration/environment-3.8.yaml b/continuous_integration/environment-3.8.yaml index fc2dbe38e89..24c3cddec10 100644 --- a/continuous_integration/environment-3.8.yaml +++ b/continuous_integration/environment-3.8.yaml @@ -42,7 +42,7 @@ dependencies: - sortedcollections - tblib - toolz - - tornado + - tornado >=6.2 - zict - zstandard >=0.9.0 - pip: diff --git a/continuous_integration/environment-3.9.yaml b/continuous_integration/environment-3.9.yaml index de834619aae..175dae3ec91 100644 --- a/continuous_integration/environment-3.9.yaml +++ b/continuous_integration/environment-3.9.yaml @@ -45,7 +45,7 @@ dependencies: - tblib - toolz - torchvision # Only tested here - - tornado + - tornado >=6.2 - zict - zstandard >=0.9.0 - pip: diff --git a/continuous_integration/recipes/distributed/meta.yaml b/continuous_integration/recipes/distributed/meta.yaml index 8cf137aadb4..9f9f9594318 100644 --- a/continuous_integration/recipes/distributed/meta.yaml +++ b/continuous_integration/recipes/distributed/meta.yaml @@ -42,7 +42,7 @@ requirements: - sortedcontainers !=2.0.0,!=2.0.1 - tblib >=1.6.0 - toolz >=0.8.2 - - tornado >=6.0.3 + - tornado >=6.2 - urllib3 - zict >=0.1.3 run_constrained: diff --git a/requirements.txt b/requirements.txt index e28e37408ee..e95aedabbb9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,7 @@ psutil >= 5.0 sortedcontainers !=2.0.0, !=2.0.1 tblib >= 1.6.0 toolz >= 0.8.2 -tornado >= 6.0.3 +tornado >= 6.2 urllib3 zict >= 0.1.3 pyyaml From 015484131d90ec8cb836078f7f73790f4a14529c Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Mon, 24 Oct 2022 14:14:36 +0100 Subject: [PATCH 4/8] WIP: Removing make_current; quite cargo-culted --- distributed/nanny.py | 4 +--- distributed/tests/test_client.py | 27 +++++++++++---------------- distributed/utils_test.py | 18 ------------------ 3 files changed, 12 insertions(+), 37 deletions(-) diff --git a/distributed/nanny.py b/distributed/nanny.py index 29e71f14c8e..ff65e29c076 100644 --- a/distributed/nanny.py +++ b/distributed/nanny.py @@ -881,9 +881,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( diff --git a/distributed/tests/test_client.py b/distributed/tests/test_client.py index 56abd05268c..8b5f272cb78 100644 --- a/distributed/tests/test_client.py +++ b/distributed/tests/test_client.py @@ -106,7 +106,6 @@ map_varying, nodebug, popen, - pristine_loop, randominc, save_sys_modules, slowadd, @@ -2208,12 +2207,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): @@ -5597,23 +5597,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 diff --git a/distributed/utils_test.py b/distributed/utils_test.py index 3bc471de19e..bd2e54fb04d 100644 --- a/distributed/utils_test.py +++ b/distributed/utils_test.py @@ -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) From 86c15d227ec23e3b59e914f18120a587de5d720d Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Wed, 2 Nov 2022 18:15:28 +0000 Subject: [PATCH 5/8] Minor test fixes --- distributed/tests/test_client.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/distributed/tests/test_client.py b/distributed/tests/test_client.py index 8b5f272cb78..83842d1894e 100644 --- a/distributed/tests/test_client.py +++ b/distributed/tests/test_client.py @@ -2207,13 +2207,11 @@ async def test_multi_client(s, a, b): def long_running_client_connection(address): - async def run(): - c = Client(address) + with Client(address) as c: 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): @@ -5597,7 +5595,7 @@ async def test_future_auto_inform(c, s, a, b): await asyncio.sleep(0.01) -def test_client_async_before_loop_starts(cleanup): +def test_client_async_in_fresh_loop(cleanup): async def run(): loop = IOLoop.current() client = Client(asynchronous=True, loop=loop) From b60d5bdbf5e0d240c1a51df255e42af620740ed1 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Wed, 2 Nov 2022 18:20:12 +0000 Subject: [PATCH 6/8] LoopRunner raises for unsupported behaviour --- distributed/utils.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/distributed/utils.py b/distributed/utils.py index b63965a8561..8842a72545e 100644 --- a/distributed/utils.py +++ b/distributed/utils.py @@ -436,12 +436,10 @@ def __init__(self, loop=None, asynchronous=False): if asynchronous: try: asyncio.get_running_loop() - except RuntimeError: - warnings.warn( - "Constructing a LoopRunner(asynchronous=True) without a running loop is deprecated", - DeprecationWarning, - stacklevel=2, - ) + except RuntimeError as e: + raise RuntimeError( + "Constructing a LoopRunner(asynchronous=True) without a running loop is not allowed" + ) from e self._loop = IOLoop.current() else: # We're expecting the loop to run in another thread, @@ -449,10 +447,8 @@ def __init__(self, loop=None, asynchronous=False): self._loop = IOLoop() else: if not loop.asyncio_loop.is_running(): - warnings.warn( - "Constructing LoopRunner(loop=loop) without a running loop is deprecated", - DeprecationWarning, - stacklevel=2, + raise RuntimeError( + "Constructing LoopRunner(loop=loop) without a running loop is not allowed" ) self._loop = loop self._asynchronous = asynchronous From abb4d9ed3ce74e67248aa2660db528f221444b47 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Thu, 10 Nov 2022 15:24:01 +0000 Subject: [PATCH 7/8] Don't pin to >=6.2 in requirements --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4930ff49d60..e571f044b04 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,7 @@ psutil >= 5.0 sortedcontainers !=2.0.0, !=2.0.1 tblib >= 1.6.0 toolz >= 0.8.2 -tornado >= 6.2 +tornado >= 6.0.3 urllib3 zict >= 0.1.3 pyyaml From f6138095493f6d2679f74e8970fcf2aeed5c98eb Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Thu, 10 Nov 2022 15:25:39 +0000 Subject: [PATCH 8/8] Remove unused symbol import --- distributed/tests/test_client.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/distributed/tests/test_client.py b/distributed/tests/test_client.py index 27645c8b5b0..2d6a2d89a0b 100644 --- a/distributed/tests/test_client.py +++ b/distributed/tests/test_client.py @@ -77,14 +77,7 @@ from distributed.metrics import time from distributed.scheduler import CollectTaskMetaDataPlugin, KilledWorker, Scheduler from distributed.sizeof import sizeof -from distributed.utils import ( - NoOpAwaitable, - get_mp_context, - is_valid_xml, - open_port, - sync, - tmp_text, -) +from distributed.utils import get_mp_context, is_valid_xml, open_port, sync, tmp_text from distributed.utils_test import ( NO_AMM, BlockedGatherDep,