Warn ontime.sleep in event loop (#63766)

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Matthias Alphart
2022-01-11 17:55:24 +01:00
committed by GitHub
parent 20bdcc7fff
commit dc58bc375a
3 changed files with 64 additions and 22 deletions

View File

@ -1,14 +1,18 @@
"""Block I/O being done in asyncio."""
"""Block blocking calls being done in asyncio."""
from http.client import HTTPConnection
import time
from .util.async_ import protect_loop
def enable() -> None:
"""Enable the detection of I/O in the event loop."""
"""Enable the detection of blocking calls in the event loop."""
# Prevent urllib3 and requests doing I/O in event loop
HTTPConnection.putrequest = protect_loop(HTTPConnection.putrequest) # type: ignore
# Prevent sleeping in event loop. Non-strict since 2022.02
time.sleep = protect_loop(time.sleep, strict=False)
# Currently disabled. pytz doing I/O when getting timezone.
# Prevent files being opened inside the event loop
# builtins.open = protect_loop(builtins.open)