Development using gunicorn + uvicorn
See original GitHub issueI’m developing an API using API Star, gunicorn, and uvicorn. I would like to make my debugging life easier.
I’m able to get tracebacks about uncalled co-routines via environment variable PYTHONASYNCIODEBUG=1
or inside the application with:
asyncio.get_event_loop().set_debug(True)
So far so good. The asyncio docs suggest to additionally enable ResourceWarning
s by running python -Wdefault [...]
. Since I’m starting the application with ["gunicorn", "-c", "gunicorn.py", "app:app"]
(inside Docker), I’m unsure how to do that. I have set
warnings.simplefilter("always", ResourceWarning)
inside my application but I don’t see any warnings. Maybe I’m failing to trigger the warning even though one of my routes awaits the following co-routine:
async def transport() -> str:
LOGGER.debug("I transport.")
trans = asyncio.Transport()
return "Rapid"
According to the asyncio docs, not closing the transport should trigger the warning. I do see the logging output 'I transport.'
.
Lastly, even with extensive configuration, I’m not seeing any uvicorn log statements. I’ve seen this mentioned around in other issues so maybe I’m just confused whether that’s solved or not. I use:
logging.dictConfig({
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': "[%(name)s] [%(levelname)s] %(message)s",
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
},
'loggers': {
'uvicorn': {
'level': 'DEBUG',
'handlers': ['console']
}
},
'root': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': True,
},
})
Adding the handler on the uvicorn
logger and separately changing the level should not be necessary due to the changes on the root
logger but I was kinda desperate to try something.
Any advice or help is greatly appreciated. I’m happy to share Dockerfile and minimal app if required.
The versions I’m using are:
Python 3.6
apistar==0.5.41
gunicorn==19.9.0
uvicorn==0.3.2
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Indeed. That’s resolved just now - version 0.3.4. Previously the debug middleware was swallowing exceptions when it returned the 500 traceback. Now we respond with the 500 traceback, but still raise the exception so that it can be caught and logged.
https://github.com/encode/uvicorn/pull/190
I guess my only remaining problem is that I’m raising an exception (
ValueError
) in one of my routes and I had expected to see mention of that in the logs in debug mode. However, I only get a server error and no mention of the exception. I can, of course, catch it and log it myself but I was curious if this is expected behaviour.