Skip to content

avoid some easy deprecated calls to asyncio.get_event_loop()#6170

Merged
mrocklin merged 2 commits intodask:mainfrom
graingert:avoid-some-deprecated-get-event-loop-calls
Apr 21, 2022
Merged

avoid some easy deprecated calls to asyncio.get_event_loop()#6170
mrocklin merged 2 commits intodask:mainfrom
graingert:avoid-some-deprecated-get-event-loop-calls

Conversation

@graingert
Copy link
Member

@graingert graingert commented Apr 21, 2022

when using asyncio.run in gen_test test that later call asyncio.get_event_loop() fail - even before python3.10:

import asyncio

async def amain():
    pass

asyncio.run(amain())
asyncio.get_event_loop()
Traceback (most recent call last):
  File "foo.py", line 7, in <module>
    asyncio.get_event_loop()
  File "/usr/lib/python3.8/asyncio/events.py", line 639, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'MainThread'.
  • use gen_test for tests that acquire IOLoop.current()
  • use get_running_loop() instead of get_event_loop()
  • use asyncio.run() instead of asyncio.get_event_loop().run_until_complete()

@graingert graingert changed the title avoid deprecated calls to asyncio.get_event_loop() avoid some easy deprecated calls to asyncio.get_event_loop() Apr 21, 2022
assert adapt.interval == 5
assert adapt.wait_count == 8
try:
adapt = Adaptive(interval="5s")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adaptive starts a PeriodicCallback - and so needs to be created in a gen_test()

@gen_test()
async def test_server_status_is_always_enum():
"""Assignments with strings is forbidden"""
server = Server({})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Server calls IOLoop.current() in the constructor



@gen_test()
async def test_server_raises_on_blocked_handlers(loop):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the loop fixture in a gen_test() test is redundant

assert p.address is None
@gen_test()
async def test_address_default_none():
async with ProcessInterface() as p:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProcessInterface calls asyncio.Lock() and asyncio.Event() in the constructor - which call get_event_loop() in py3.8-3.9

@graingert graingert requested a review from fjetter April 21, 2022 13:27
@github-actions
Copy link
Contributor

Unit Test Results

       16 files  +       2         16 suites  +2   7h 14m 42s ⏱️ + 49m 33s
  2 727 tests ±       0    2 646 ✔️ +       1       81 💤  -     1  0 ±0 
21 701 runs  +2 381  20 665 ✔️ +2 281  1 036 💤 +100  0 ±0 

Results for commit a45f4f3. ± Comparison against base commit b85f2ed.

@mrocklin
Copy link
Member

These seem innocuous to me. Tests pass. Merging.

Thanks @graingert

@mrocklin mrocklin merged commit 6947873 into dask:main Apr 21, 2022
@graingert graingert deleted the avoid-some-deprecated-get-event-loop-calls branch April 21, 2022 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants