from typing import Tuple
import asyncio


def _get_event_loop() -> Tuple[asyncio.AbstractEventLoop, bool]:
  """Returns an event loop and whether the loop should be closed once done."""
  try:
    loop = asyncio.get_event_loop()
    if loop.is_closed():
      loop = asyncio.new_event_loop()
      should_close_loop = True
    else:
      should_close_loop = False
  except RuntimeError:
    loop = asyncio.new_event_loop()
    should_close_loop = True
  return loop, should_close_loop