changeset: 95294:7f1015e4277a parent: 95292:28b465d8c519 parent: 95293:9d3013a383eb user: Victor Stinner date: Mon Mar 30 11:19:07 2015 +0200 files: Python/random.c description: (Merge 3.4) Issue #22585: os.urandom() now releases the GIL when the getentropy() is used (OpenBSD 5.6+). diff -r 28b465d8c519 -r 7f1015e4277a Python/random.c --- a/Python/random.c Mon Mar 30 11:16:40 2015 +0200 +++ b/Python/random.c Mon Mar 30 11:19:07 2015 +0200 @@ -81,16 +81,24 @@ { while (size > 0) { Py_ssize_t len = Py_MIN(size, 256); - int res = getentropy(buffer, len); - if (res < 0) { - if (fatal) { - Py_FatalError("getentropy() failed"); - } - else { + int res; + + if (!fatal) { + Py_BEGIN_ALLOW_THREADS + res = getentropy(buffer, len); + Py_END_ALLOW_THREADS + + if (res < 0) { PyErr_SetFromErrno(PyExc_OSError); return -1; } } + else { + res = getentropy(buffer, len); + if (res < 0) + Py_FatalError("getentropy() failed"); + } + buffer += len; size -= len; }