]> git.ipfire.org Git - people/ms/westferry.git/commitdiff
services: Make the webapp fully async
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 May 2025 14:23:55 +0000 (14:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 May 2025 14:23:55 +0000 (14:23 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/scripts/westferry.in
src/westferry/services.py

index 12bc86a1caca96fc2c3c69d26c2139cac547fe8a..b4bd01c36328cb533780697d8b943d8541ec3fec 100644 (file)
 #                                                                             #
 ###############################################################################
 
+import asyncio
 import westferry
 
-s = westferry.services.WebService(debug=True)
-s.run()
+async def run():
+       # Create the web service
+       s = westferry.services.WebService(debug=True)
+
+       # Run the service
+       await s.run()
+
+asyncio.run(run())
index aa2afd9d21fb9d1e31c95f96c10caa13163627cf..bf6d2c90abaa039cb74303f859a1e44731e0827b 100644 (file)
@@ -19,8 +19,7 @@
 #                                                                             #
 ###############################################################################
 
-import tornado.httpserver
-import tornado.ioloop
+import asyncio
 
 from . import application
 
@@ -36,19 +35,11 @@ class WebService(Service):
        def make_application(self, **kwargs):
                return application.WebApplication(**kwargs)
 
-       @property
-       def ioloop(self):
-               return tornado.ioloop.IOLoop.instance()
-
-       def run(self, **kwargs):
+       async def run(self, **kwargs):
                app = self.make_application(debug=self.debug, **kwargs)
 
-               # Create a HTTP server instance
-               server = tornado.httpserver.HTTPServer(app)
-               server.bind(self.port)
-
-               # Launch the server
-               server.start()
+               # Listen on the configured port
+               app.listen(self.port, xheaders=True)
 
-               # Launch the IOLoop
-               self.ioloop.start()
+               # Wait for forever
+               await asyncio.Event().wait()