Skip to content

Commit

Permalink
fixes VirusTotal#46 - recreate event loop also when loop is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
artur-augustyniak committed May 6, 2022
1 parent 5b4e0b7 commit 638e1b8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion vt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 638e1b8

Please sign in to comment.