Skip to content

Commit

Permalink
Do not change polices in the case of custom loop provided. (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellysmile committed Jun 1, 2020
1 parent 7af0edb commit c7e77d6
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions aiorun.py
Expand Up @@ -160,12 +160,18 @@ def run(
"exclusive. (Just make your own uvloop and pass it in)."
)

if use_uvloop:
import uvloop
loop_was_supplied = bool(loop)

asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
else:
asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
if not loop_was_supplied:
if use_uvloop:
import uvloop

asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
else:
asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

if loop and loop.get_exception_handler() and stop_on_unhandled_errors:
raise Exception(
Expand All @@ -174,11 +180,6 @@ def run(
"parameter is unavailable (all exceptions will be handled)."
)

loop_was_supplied = bool(loop)
if not loop_was_supplied:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

pending_exception_to_raise = None

def custom_exception_handler(loop, context: dict):
Expand Down

0 comments on commit c7e77d6

Please sign in to comment.