[New-bugs-announce] [issue23172] Bad file descriptor error occurs if random library is imported before closing FDs

Wayne Song report at bugs.python.org
Mon Jan 5 22:12:41 CET 2015


New submission from Wayne Song:

The following script:

import os
import resource
import random

print("1")

for fd in range(resource.getrlimit(resource.RLIMIT_NOFILE)[0]):
    try:
        if fd not in range(0, 3):
            os.close(fd)
    except os.error:
        pass

print("2")
print(os.urandom(32))
print("3")

Crashes with the following output:

1
2
Traceback (most recent call last):
  File "test.py", line 17, in <module>
    print(os.urandom(32))
OSError: [Errno 9] Bad file descriptor

On an Ubuntu 14.04 install (in VirtualBox).  It seems to run correctly on Mac OS X.  The script runs fine if I don't import random at the top.

----------
components: Library (Lib)
messages: 233478
nosy: waynesong
priority: normal
severity: normal
status: open
title: Bad file descriptor error occurs if random library is imported before closing FDs
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23172>
_______________________________________


More information about the New-bugs-announce mailing list