Skip to content

Commit

Permalink
Python web frameworks doesn't generate an event loop. Allow them to w…
Browse files Browse the repository at this point in the history
…ork with asyncio (#23)
  • Loading branch information
chexca authored May 28, 2020
1 parent 7f7a3cb commit 098f383
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion vt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@

def _make_sync(future):
"""Utility function that waits for an async call, making it sync."""
return asyncio.get_event_loop().run_until_complete(future)
try:
event_loop = asyncio.get_event_loop()
except RuntimeError:
# Generate an event loop if there isn't any.
event_loop = asyncio.new_event_loop()
asyncio.set_event_loop(event_loop)
return event_loop.run_until_complete(future)


def url_id(url):
Expand Down

0 comments on commit 098f383

Please sign in to comment.