From: Victor Stinner Date: Mon, 30 Mar 2015 09:16:40 +0000 (+0200) Subject: Issue #22181: os.urandom() now releases the GIL when the getrandom() X-Git-Tag: v3.5.0a4~261 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=79b74aeb20a539cb807aa297dc22eabbb525b892;p=thirdparty%2FPython%2Fcpython.git Issue #22181: os.urandom() now releases the GIL when the getrandom() implementation is used. --- diff --git a/Python/random.c b/Python/random.c index a4eba3ccd93b..f3a8ae552e1c 100644 --- a/Python/random.c +++ b/Python/random.c @@ -115,9 +115,18 @@ py_getrandom(void *buffer, Py_ssize_t size, int raise) while (0 < size) { errno = 0; - /* the libc doesn't expose getrandom() yet, see: + + /* Use syscall() because the libc doesn't expose getrandom() yet, see: * https://sourceware.org/bugzilla/show_bug.cgi?id=17252 */ - n = syscall(SYS_getrandom, buffer, size, flags); + if (raise) { + Py_BEGIN_ALLOW_THREADS + n = syscall(SYS_getrandom, buffer, size, flags); + Py_END_ALLOW_THREADS + } + else { + n = syscall(SYS_getrandom, buffer, size, flags); + } + if (n < 0) { if (errno == ENOSYS) { getrandom_works = 0;