From 3ef3ac855e0e077496871bca692d752261527618 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Wed, 25 Sep 2019 11:00:45 +0200 Subject: [PATCH] Avoid "RuntimeError: Event loop is closed" Triggered by pytest now. Signed-off-by: Jan Kiszka --- kas/kas.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kas/kas.py b/kas/kas.py index b3c8da1..fa0066d 100644 --- a/kas/kas.py +++ b/kas/kas.py @@ -95,8 +95,9 @@ def _atexit_handler(): """ loop = asyncio.get_event_loop() pending = asyncio.Task.all_tasks() - loop.run_until_complete(asyncio.gather(*pending)) - loop.close() + if not loop.is_closed(): + loop.run_until_complete(asyncio.gather(*pending)) + loop.close() def kas_get_argparser():