[Python-checkins] cpython (2.7): Issue #23115: os.urandom() now releases the GIL when the getentropy() is used

victor.stinner python-checkins at python.org
Mon Mar 30 11:23:00 CEST 2015


https://hg.python.org/cpython/rev/05b96af72805
changeset: 95295:05b96af72805
branch: 2.7
parent: 95284:12d3eec72f9e
user: Victor Stinner <victor.stinner at gmail.com>
date: Mon Mar 30 11:22:13 2015 +0200
summary:
 Issue #23115: os.urandom() now releases the GIL when the getentropy() is used
(OpenBSD 5.6+).
files:
 Python/random.c | 20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/Python/random.c b/Python/random.c
--- a/Python/random.c
+++ b/Python/random.c
@@ -103,16 +103,24 @@
 {
 while (size > 0) {
 Py_ssize_t len = size < 256 ? 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;
 }
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /