From: Michael Tremer Date: Fri, 9 May 2025 14:23:55 +0000 (+0000) Subject: services: Make the webapp fully async X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=371806c1165297baee395a6bf228f485ff1d222c;p=people%2Fms%2Fwestferry.git services: Make the webapp fully async Signed-off-by: Michael Tremer --- diff --git a/src/scripts/westferry.in b/src/scripts/westferry.in index 12bc86a..b4bd01c 100644 --- a/src/scripts/westferry.in +++ b/src/scripts/westferry.in @@ -19,7 +19,14 @@ # # ############################################################################### +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()) diff --git a/src/westferry/services.py b/src/westferry/services.py index aa2afd9..bf6d2c9 100644 --- a/src/westferry/services.py +++ b/src/westferry/services.py @@ -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()