[Python-checkins] cpython: Issue #14107: test: Fix a deadlock involving the memory watchdog thread.

charles-francois.natali python-checkins at python.org
Sun Feb 26 17:28:37 CET 2012


http://hg.python.org/cpython/rev/52dc4fcd0d6f
changeset:   75295:52dc4fcd0d6f
user:        Charles-François Natali <neologix at free.fr>
date:        Sun Feb 26 17:27:32 2012 +0100
summary:
  Issue #14107: test: Fix a deadlock involving the memory watchdog thread.

files:
  Lib/test/support.py |  10 ++++++++++
  1 files changed, 10 insertions(+), 0 deletions(-)


diff --git a/Lib/test/support.py b/Lib/test/support.py
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -45,6 +45,11 @@
 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 @@
             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)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list