Skip to content
Discussion options

You must be logged in to vote

Hey there!

You shouldn't try to use warnings.catch_warnings() in anything that expects to run more than one thing during the same period of time, like a web API handling requests. It is not thread-safe, so it's not concurrent-safe, it's only for smaller or simpler scripts, during testing or so. You can read more in the official docs for warnings, in the last note: https://docs.python.org/3/library/warnings.html#available-context-managers

For what you are doing, if you want to capture warnings per-request in a similar way, you would have to create your own utils equivalent to:

  • Create a context var to store the warnings per request
  • Set the context var to a list or similar in the middleware…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by tiangolo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
2 participants