Queer European MD passionate about IT
Sfoglia il codice sorgente

Added function to run aiohttp web apps in dedicated threads.

Davte 5 anni fa
parent
commit
9f91114e0e
1 ha cambiato i file con 10 aggiunte e 0 eliminazioni
  1. 10 0
      davtelepot/utilities.py

+ 10 - 0
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)