New submission from jan matejek:

When imported, the random module creates and seeds an implicit instance, even 
when it is never used.

The RNG is seeded from os.urandom, which as of python 3.5 uses the potentially 
blocking getrandom() call.

This causes problems e.g. on our build VMs that don't have true entropy, so 
getrandom() blocks forever -- unlike /dev/urandom, getrandom() in kernel waits 
until 128 bits of true entropy are available to reseed the RNG. And as it 
happens, the usual setup.py will very indirectly "import random" somewhere deep 
in its dependencies.

I can foresee a similar issue if someone uses python early in the boot process.

A possible workaround is to monkeypatch os.urandom (in this particular case, to 
return a string of zeroes and remove randomness entirely to get reproducible 
builds)

----------
components: Library (Lib)
messages: 253073
nosy: matejcik
priority: normal
severity: normal
status: open
title: "import random" blocks on entropy collection
type: behavior
versions: Python 3.5

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25420>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to