Patch http.client to not do I/O in the event loop (#34194)

This commit is contained in:
Paulus Schoutsen 2020-04-15 15:32:10 -07:00 committed by GitHub
parent 5bfc1f3d4d
commit d011b46985
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 163 additions and 3 deletions

View file

@ -0,0 +1,14 @@
"""Block I/O being done in asyncio."""
from http.client import HTTPConnection
from homeassistant.util.async_ import protect_loop
def enable() -> None:
"""Enable the detection of I/O in the event loop."""
# Prevent urllib3 and requests doing I/O in event loop
HTTPConnection.putrequest = protect_loop(HTTPConnection.putrequest)
# Currently disabled. pytz doing I/O when getting timezone.
# Prevent files being opened inside the event loop
# builtins.open = protect_loop(builtins.open)