diff options
author | Charles-François Natali <neologix@free.fr> | 2012-02-26 16:27:32 (GMT) |
---|---|---|
committer | Charles-François Natali <neologix@free.fr> | 2012-02-26 16:27:32 (GMT) |
commit | 9578757ec4892cfdad29a748f88344f65aa2efbb (patch) | |
tree | 0e55a6418a5b3005e7c9caae0bde5772b2260d39 /Lib/test/support.py | |
parent | c45a8a153bf20515060c2056308b46caccd959e0 (diff) | |
download | cpython-9578757ec4892cfdad29a748f88344f65aa2efbb.zip cpython-9578757ec4892cfdad29a748f88344f65aa2efbb.tar.gz cpython-9578757ec4892cfdad29a748f88344f65aa2efbb.tar.bz2 |
Issue #14107: test: Fix a deadlock involving the memory watchdog thread.
Diffstat (limited to 'Lib/test/support.py')
-rw-r--r-- | Lib/test/support.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py index 47b94ca..c384222 100644 --- a/Lib/test/support.py +++ b/Lib/test/support.py @@ -45,6 +45,11 @@ try: except ImportError: zlib = None +try: + import fcntl +except ImportError: + fcntl = None + __all__ = [ "Error", "TestFailed", "ResourceDenied", "import_module", "verbose", "use_resources", "max_memuse", "record_original_stdout", @@ -1184,6 +1189,11 @@ class _MemoryWatchdog: sys.stderr.flush() return pipe_fd, wfd = os.pipe() + # set the write end of the pipe non-blocking to avoid blocking the + # watchdog thread when the consumer doesn't drain the pipe fast enough + if fcntl: + flags = fcntl.fcntl(wfd, fcntl.F_GETFL) + fcntl.fcntl(wfd, fcntl.F_SETFL, flags|os.O_NONBLOCK) # _file_watchdog() doesn't take the GIL in its child thread, and # therefore collects statistics timely faulthandler._file_watchdog(rfd, wfd, 1.0) |