Log directory blocking I/O functions that run in the event loop (#118529)

* Log directory I/O functions that run in the event loop

* tests
This commit is contained in:
J. Nick Koston
2024-05-31 10:09:19 -05:00
committed by GitHub
parent 1fef4fa1f6
commit 6656f7d6b9
2 changed files with 71 additions and 0 deletions

View File

@ -2,8 +2,10 @@
import builtins
from contextlib import suppress
import glob
from http.client import HTTPConnection
import importlib
import os
import sys
import threading
import time
@ -59,8 +61,22 @@ def enable() -> None:
loop_thread_id=loop_thread_id,
)
glob.glob = protect_loop(
glob.glob, strict_core=False, strict=False, loop_thread_id=loop_thread_id
)
glob.iglob = protect_loop(
glob.iglob, strict_core=False, strict=False, loop_thread_id=loop_thread_id
)
if not _IN_TESTS:
# Prevent files being opened inside the event loop
os.listdir = protect_loop( # type: ignore[assignment]
os.listdir, strict_core=False, strict=False, loop_thread_id=loop_thread_id
)
os.scandir = protect_loop( # type: ignore[assignment]
os.scandir, strict_core=False, strict=False, loop_thread_id=loop_thread_id
)
builtins.open = protect_loop( # type: ignore[assignment]
builtins.open,
strict_core=False,