ASGI working
This commit is contained in:
		| @@ -1037,8 +1037,8 @@ class Sanic(BaseSanic): | ||||
|         details: https://asgi.readthedocs.io/en/latest/""" | ||||
|         # raise Exception("call") | ||||
|         self.asgi = True | ||||
|         self.router.finalize() | ||||
|         asgi_app = await ASGIApp.create(self, scope, receive, send) | ||||
|         self._asgi_app = await ASGIApp.create(self, scope, receive, send) | ||||
|         asgi_app = self._asgi_app | ||||
|         await asgi_app() | ||||
|  | ||||
|     # _asgi_single_callable = True  # We conform to ASGI 3.0 single-callable | ||||
|   | ||||
| @@ -131,7 +131,6 @@ class Lifespan: | ||||
|         in sequence since the ASGI lifespan protocol only supports a single | ||||
|         startup event. | ||||
|         """ | ||||
|         print(">>> starting up") | ||||
|         self.asgi_app.sanic_app.router.finalize() | ||||
|         listeners = self.asgi_app.sanic_app.listeners.get( | ||||
|             "before_server_start", [] | ||||
| @@ -192,7 +191,6 @@ class ASGIApp: | ||||
|     async def create( | ||||
|         cls, sanic_app, scope: ASGIScope, receive: ASGIReceive, send: ASGISend | ||||
|     ) -> "ASGIApp": | ||||
|         raise Exception("create") | ||||
|         instance = cls() | ||||
|         instance.sanic_app = sanic_app | ||||
|         instance.transport = MockTransport(scope, receive, send) | ||||
| @@ -206,7 +204,6 @@ class ASGIApp: | ||||
|             ] | ||||
|         ) | ||||
|         instance.lifespan = Lifespan(instance) | ||||
|         print(instance.lifespan) | ||||
|  | ||||
|         if scope["type"] == "lifespan": | ||||
|             await instance.lifespan(scope, receive, send) | ||||
| @@ -296,5 +293,4 @@ class ASGIApp: | ||||
|         """ | ||||
|         Handle the incoming request. | ||||
|         """ | ||||
|         print("......") | ||||
|         await self.sanic_app.handle_request(self.request) | ||||
|   | ||||
| @@ -137,6 +137,7 @@ class GunicornWorker(base.Worker): | ||||
|             await _shutdown | ||||
|  | ||||
|     async def _run(self): | ||||
|         self.app.router.finalize() | ||||
|         for sock in self.sockets: | ||||
|             state = dict(requests_count=0) | ||||
|             self._server_settings["host"] = None | ||||
|   | ||||
| @@ -54,7 +54,6 @@ def test_listeners_triggered(): | ||||
|  | ||||
|     @app.listener("before_server_start") | ||||
|     def do_before_server_start(*args, **kwargs): | ||||
|         raise Exception("......") | ||||
|         nonlocal before_server_start | ||||
|         before_server_start = True | ||||
|  | ||||
| @@ -73,6 +72,10 @@ def test_listeners_triggered(): | ||||
|         nonlocal after_server_stop | ||||
|         after_server_stop = True | ||||
|  | ||||
|     @app.route("/") | ||||
|     def handler(request): | ||||
|         return text("...") | ||||
|  | ||||
|     class CustomServer(uvicorn.Server): | ||||
|         def install_signal_handlers(self): | ||||
|             pass | ||||
| @@ -80,8 +83,8 @@ def test_listeners_triggered(): | ||||
|     config = uvicorn.Config(app=app, loop="asyncio", limit_max_requests=0) | ||||
|     server = CustomServer(config=config) | ||||
|  | ||||
|     # with pytest.warns(UserWarning): | ||||
|     server.run() | ||||
|     with pytest.warns(UserWarning): | ||||
|         server.run() | ||||
|  | ||||
|     all_tasks = ( | ||||
|         asyncio.Task.all_tasks() | ||||
| @@ -123,6 +126,10 @@ def test_listeners_triggered_async(app): | ||||
|         nonlocal after_server_stop | ||||
|         after_server_stop = True | ||||
|  | ||||
|     @app.route("/") | ||||
|     def handler(request): | ||||
|         return text("...") | ||||
|  | ||||
|     class CustomServer(uvicorn.Server): | ||||
|         def install_signal_handlers(self): | ||||
|             pass | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Adam Hopkins
					Adam Hopkins