]> granicus.if.org Git - python/commitdiff
Issue 3551: Raise ValueError if the size causes ERROR_NO_SYSTEM_RESOURCES
authorJesse Noller <jnoller@gmail.com>
Thu, 2 Apr 2009 04:22:09 +0000 (04:22 +0000)
committerJesse Noller <jnoller@gmail.com>
Thu, 2 Apr 2009 04:22:09 +0000 (04:22 +0000)
Doc/library/multiprocessing.rst
Misc/NEWS
Modules/_multiprocessing/connection.h
Modules/_multiprocessing/pipe_connection.c

index 5ff94eaea23e4f92843ee2be1a5929fc064f275a..18e81a793858b01b2a14ed04d27ae6818cc9f685 100644 (file)
@@ -710,7 +710,8 @@ Connection objects usually created using :func:`Pipe` -- see also
       Send an object to the other end of the connection which should be read
       using :meth:`recv`.
 
-      The object must be picklable.
+      The object must be picklable.  Very large pickles (approximately 32 MB+,
+      though it depends on the OS) may raise a ValueError exception.
 
    .. method:: recv()
 
@@ -742,7 +743,9 @@ Connection objects usually created using :func:`Pipe` -- see also
       complete message.
 
       If *offset* is given then data is read from that position in *buffer*.  If
-      *size* is given then that many bytes will be read from buffer.
+      *size* is given then that many bytes will be read from buffer.  Very large
+      buffers (approximately 32 MB+, though it depends on the OS) may raise a
+      ValueError exception
 
    .. method:: recv_bytes([maxlength])
 
index dd8c0ade99a4712e50d430aed597f48cc0f35362..8a500597db9daef50bc8ee2d21930847fea4330c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -202,6 +202,10 @@ Core and Builtins
 Library
 -------
 
+- Issue 3551: Patch multiprocessing to raise a proper exception if the size of the
+  object when writefile is called causes a ERROR_NO_SYSTEM_RESOURCES. Added docs
+  to note the limitation
+
 - unittest.assertNotEqual() now uses the inequality operator (!=) instead 
   of the equality operator.
   
index 458d1d3cf306260c68e29d64b56b80c000c0330e..c2f85635ad75d18e1b14a4f6e198649dff8f787b 100644 (file)
@@ -131,8 +131,12 @@ connection_sendbytes(ConnectionObject *self, PyObject *args)
 
        res = conn_send_string(self, buffer + offset, size);
 
-       if (res < 0)
-               return mp_SetError(PyExc_IOError, res);
+       if (res < 0) {
+               if (PyErr_Occurred())
+                       return NULL;
+               else
+                       return mp_SetError(PyExc_IOError, res);
+       }
 
        Py_RETURN_NONE;
 }
index 27e79dda7d4a11823e8f56b93970f0a15cf9738c..66947c838f2c8d58df1635eda1e35030a27ccc1a 100644 (file)
@@ -23,6 +23,12 @@ conn_send_string(ConnectionObject *conn, char *string, size_t length)
        Py_BEGIN_ALLOW_THREADS
        ret = WriteFile(conn->handle, string, length, &amount_written, NULL);
        Py_END_ALLOW_THREADS
+
+       if (ret == 0 && GetLastError() == ERROR_NO_SYSTEM_RESOURCES) {
+               PyErr_Format(PyExc_ValueError, "Cannnot send %" PY_FORMAT_SIZE_T "d bytes over connection", length);
+               return MP_STANDARD_ERROR;
+       }
+
        return ret ? MP_SUCCESS : MP_STANDARD_ERROR;
 }