[Python-checkins] cpython: Issue #19565: Prevent warnings at shutdown about pending overlapped ops.

richard.oudkerk python-checkins at python.org
Sun Nov 17 14:24:31 CET 2013


http://hg.python.org/cpython/rev/da10196b94f4
changeset:   87201:da10196b94f4
parent:      87199:c1f2b3fc965d
user:        Richard Oudkerk <shibturn at gmail.com>
date:        Sun Nov 17 13:15:51 2013 +0000
summary:
  Issue #19565: Prevent warnings at shutdown about pending overlapped ops.

files:
  Modules/_winapi.c |  36 +++++++++++++++++++++++++++-------
  1 files changed, 28 insertions(+), 8 deletions(-)


diff --git a/Modules/_winapi.c b/Modules/_winapi.c
--- a/Modules/_winapi.c
+++ b/Modules/_winapi.c
@@ -107,17 +107,37 @@
 {
     DWORD bytes;
     int err = GetLastError();
+
     if (self->pending) {
-        /* make it a programming error to deallocate while operation
-           is pending, even if we can safely cancel it */
         if (check_CancelIoEx() &&
-                Py_CancelIoEx(self->handle, &self->overlapped))
-            GetOverlappedResult(self->handle, &self->overlapped, &bytes, TRUE);
-        PyErr_SetString(PyExc_RuntimeError,
-                        "I/O operations still in flight while destroying "
-                        "Overlapped object, the process may crash");
-        PyErr_WriteUnraisable(NULL);
+            Py_CancelIoEx(self->handle, &self->overlapped) &&
+            GetOverlappedResult(self->handle, &self->overlapped, &bytes, TRUE))
+        {
+            /* The operation is no longer pending -- nothing to do. */
+        }
+        else if (_Py_Finalizing == NULL)
+        {
+            /* The operation is still pending -- give a warning.  This
+               will probably only happen on Windows XP. */
+            PyErr_SetString(PyExc_RuntimeError,
+                            "I/O operations still in flight while destroying "
+                            "Overlapped object, the process may crash");
+            PyErr_WriteUnraisable(NULL);
+        }
+        else
+        {
+            /* The operation is still pending, but the process is
+               probably about to exit, so we need not worry too much
+               about memory leaks.  Leaking self prevents a potential
+               crash.  This can happen when a daemon thread is cleaned
+               up at exit -- see #19565.  We only expect to get here
+               on Windows XP. */
+            CloseHandle(self->overlapped.hEvent);
+            SetLastError(err);
+            return;
+        }
     }
+
     CloseHandle(self->overlapped.hEvent);
     SetLastError(err);
     if (self->write_buffer.obj)

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


More information about the Python-checkins mailing list