Author larry
Recipients Theodore Tso, dstufft, larry, vstinner
Date 2016-06-08.23:14:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
os.getrandom() would be a thin shell around what the local OS provides, and has the advantage of behaving in a predictable manner.  If you provide block=, its implementation and semantics will vary wildly between platforms.

* On Linux, block=False should be the default.  block=True means it will use getrandom(), and block=False means it will use /dev/urandom except possibly getrandom().

* On FreeBSD, block=True will be the default, and block=False will either be ignored, or return an empty string (or throw an exception, depending on what would be a better error-handling mechanism, IDK).

* On OS X, block=False would be the default, and block=True would be ignored, because the interface doesn't permit blocking to wait for additional entropy and generating higher-quality random bits.

So, yes, the os module should *expose* the behavior of the underlying OS, rather than trying to paper over it.

> there is a lot of code out there using os.urandom for it's security properties

This is exactly why we should not change the behavior of os.urandom().  os.urandom() must not block on Linux.  So defaulting to block=True on Linux is a non-starter.

The argument "if we add a block parameter, then users can use it and benefit", is equivalent to saying "if we add a new function os.getrandom(), then users can use it and benefit".  The user needs to be educated, and we can do that with either approach.

However, if users want to write backwards-compatible code, it's a lot easier to detect the presence or lack of a new function (hasattr(os, "getrandom")) than to detect the presence or lack of a new parameter to an existing function (which, if we're lucky, we could do with inspect.signature, and if we're unlucky involves a try/except block).
Date User Action Args
2016-06-08 23:14:17larrysetrecipients: + larry, vstinner, dstufft, Theodore Tso
2016-06-08 23:14:17larrysetmessageid: <>
2016-06-08 23:14:17larrylinkissue27266 messages
2016-06-08 23:14:16larrycreate