Since the lifespan protocol is new, some ASGI frameworks have not implemented it. It would be nice to have a configuration option to disable lifespan so that no errors are thrown.
The example in the README doesn't work any more - if I try to run it I get this error:
$ uvicorn app:App --port 8005
INFO: Started server process [31803]
INFO: Waiting for application startup.
ERROR: Exception in 'lifespan' protocol
Traceback (most recent call last):
File "/Users/simonw/.local/share/virtualenvs/datasette-oJRYYJuA/lib/python3.7/site-packages/uvicorn/lifespan.py", line 29, in run
await self.asgi(self.receive, self.send)
File "./app2.py", line 10, in __call__
[b'content-type', b'text/plain'],
File "/Users/simonw/.local/share/virtualenvs/datasette-oJRYYJuA/lib/python3.7/site-packages/uvicorn/lifespan.py", line 50, in send
raise RuntimeError(error % message['type'])
RuntimeError: Got invalid message type on lifespan protocol "http.response.start"
ERROR: Application startup failed. Exiting.
I could work around the issue the README has with uvicorn==0.3.22.
@simonw Thanks yup. I've updated that now.
(It should raise an error on anything except HTTP messsges, which will cause the lifespan protocol to be ignored.)
Agree that we should have an option for this. #262 gets most of the way there, except that it's important that we default to having it on.
Now available as --disable-lifespan
Most helpful comment
The example in the README doesn't work any more - if I try to run it I get this error: