httpx
httpx copied to clipboard
Detect blocking calls in coroutines during tests using BlockBuster
trafficstars
Summary
BlockBuster is a library to detect harmful blocking calls done in the async event loop (when activated, it raises an error if a blocking call is done).
It is just a few lines to integrate with pytest.
Globally, httpx is a good citizen and the only blocking call it detected is mimetypes.guess_type in Request constructor. mimetypes has a global cache so this blocking call is only done once.
Solutions for this would be:
- defer the mimetype resolution to when the request is actually called and call
mimetypes.guess_typein a thread - or just accept that it blocks for a short time only once and add an exemption in blockbuster setup. I've also seen blocking calls made when using HTTPS but there seems to be no unit tests for async+TLS.
Checklist
- [x] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
- [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
- [x] I've updated the documentation accordingly.