From 638e1b8df3bfac22dc0c46a1a1e8059e1731989e Mon Sep 17 00:00:00 2001 From: Artur Augustyniak Date: Fri, 6 May 2022 11:54:21 +0200 Subject: [PATCH] fixes #46 - recreate event loop also when loop is closed --- vt/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vt/utils.py b/vt/utils.py index dc95578..8a6ceae 100644 --- a/vt/utils.py +++ b/vt/utils.py @@ -19,8 +19,13 @@ def make_sync(future): """Utility function that waits for an async call, making it sync.""" try: event_loop = asyncio.get_event_loop() + ''' + Closed event loop is not NX loop, so Runtime exceptiion will be never thrown. + ''' + if event_loop.is_closed(): + raise RuntimeError("event loop is closed") except RuntimeError: - # Generate an event loop if there isn't any. + # Generate an event loop if there isn't any or event loop is closed. event_loop = asyncio.new_event_loop() asyncio.set_event_loop(event_loop) return event_loop.run_until_complete(future)