From c7e77d688ff0a724f64a35f2fa3cc93a1188e513 Mon Sep 17 00:00:00 2001 From: Victor K Date: Mon, 1 Jun 2020 05:53:18 -0400 Subject: [PATCH] Do not change polices in the case of custom loop provided. (#46) --- aiorun.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/aiorun.py b/aiorun.py index 39f86d6..7c97a66 100644 --- a/aiorun.py +++ b/aiorun.py @@ -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( @@ -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):