From cda56a8ddf7be78027c047ca155cefe9b9e71e28 Mon Sep 17 00:00:00 2001 From: Dan King Date: Tue, 24 Oct 2023 23:49:33 -0400 Subject: [PATCH] push me in the AM --- hail/python/hailtop/__init__.py | 20 +++----------------- hail/python/hailtop/fs/fs_utils.py | 2 +- hail/python/hailtop/httpx.py | 2 +- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/hail/python/hailtop/__init__.py b/hail/python/hailtop/__init__.py index 6f29c35716f..4065957f554 100644 --- a/hail/python/hailtop/__init__.py +++ b/hail/python/hailtop/__init__.py @@ -27,34 +27,20 @@ def is_notebook() -> bool: return IS_NOTEBOOK -_hail_created_the_main_thread_event_loop = False - - def hail_event_loop(): - '''If an event loop exists and Hail did not create it, use nest_asyncio to allow Hail's event - loops to nest inside it. - - If an event loop exists and Hail did create it, then a developer is trying to use async inside - sync inside async. That is forbidden. + '''If a running event loop exists, use nest_asyncio to allow Hail's event loops to nest inside + it. If no event loop exists, ask asyncio to get one for us. ''' - global _hail_created_the_main_thread_event_loop - import asyncio # pylint: disable=import-outside-toplevel import nest_asyncio # pylint: disable=import-outside-toplevel try: asyncio.get_running_loop() - if _hail_created_the_main_thread_event_loop: - raise ValueError( - 'As a matter of Hail team policy, you are not allowed to nest asynchronous Hail code ' - 'inside synchronous Hail code.' - ) - nest_asyncio.apply() return asyncio.get_running_loop() - except RuntimeError as err: + except RuntimeError: return asyncio.get_event_loop() diff --git a/hail/python/hailtop/fs/fs_utils.py b/hail/python/hailtop/fs/fs_utils.py index ae8decde228..b12ab41109b 100644 --- a/hail/python/hailtop/fs/fs_utils.py +++ b/hail/python/hailtop/fs/fs_utils.py @@ -12,7 +12,7 @@ def _fs() -> RouterFS: '''Return an FS for this particular thread.''' - global _router_fs + global _router_fs_for_loop loop = hail_event_loop() if fs := _router_fs_for_loop.get(loop): diff --git a/hail/python/hailtop/httpx.py b/hail/python/hailtop/httpx.py index 284adb63568..5bc0f6487b0 100644 --- a/hail/python/hailtop/httpx.py +++ b/hail/python/hailtop/httpx.py @@ -93,7 +93,7 @@ def __init__(self, **kwargs): try: self.loop_at_creation_time = asyncio.get_running_loop() - except RuntimeError as err: + except RuntimeError: raise ValueError( 'aiohttp.ClientSession stashes a copy of the event loop into a field. Very confusing ' 'errors arise if that stashed event loop differs from the currently running one. '