New submission from Ian Wienand <i...@wienand.org>: Hi,
Lib/random.py has a fallback if os.urandom() returns NotImplementedError --- from os import urandom as _urandom ... def seed(self, a=None): if a is None: try: a = long(_hexlify(_urandom(16)), 16) except NotImplementedError: import time a = long(time.time() * 256) # use fractional seconds --- In 2.6, this is indeed what happens in Lib/os.py where "import urandom from os" gets [2]: --- if not _exists("urandom"): def urandom(n): ... try: _urandomfd = open("/dev/urandom", O_RDONLY) except (OSError, IOError): raise NotImplementedError("/dev/urandom (or equivalent) not found") --- however, in 2.7, things have shuffled around as a result of issue Issue #13703 and now _PyOS_URandom will return an OSError if it can't find /dev/urandom [3]. This means if you "import random" without "/dev/urandom" available it crashes trying to seed I'm not sure if this is intentional? One easy solution would be to catch OSError in random.py and fall back then too [1] http://hg.python.org/cpython/file/70274d53c1dd/Python/random.c#l227 [2] http://hg.python.org/cpython/file/9f8771e09052/Lib/os.py#l746 [3] http://hg.python.org/cpython/file/70274d53c1dd/Lib/random.py#l111 ---------- components: Library (Lib) messages: 165340 nosy: iwienand priority: normal severity: normal status: open title: OSError with "import random" when /dev/urandom doesn't exist (regression from 2.6) versions: Python 2.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue15340> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com