From 9f91114e0e4cb086f45e5c72875fadb232d4a7b2 Mon Sep 17 00:00:00 2001 From: Davte Date: Fri, 7 Jun 2019 21:12:17 +0200 Subject: [PATCH] Added function to run aiohttp web apps in dedicated threads. --- davtelepot/utilities.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/davtelepot/utilities.py b/davtelepot/utilities.py index 50dbf01..5c4b79a 100644 --- a/davtelepot/utilities.py +++ b/davtelepot/utilities.py @@ -1457,3 +1457,13 @@ def pick_most_similar_from_list(list_, item): element ) ) + + +def run_aiohttp_server(app, *args, **kwargs): + """Run an aiohttp web app, with its positional and keyword arguments. + + Useful to run apps in dedicated threads. + """ + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + web.run_app(app, *args, **kwargs)