Message24898
Logged In: YES
user_id=110477
Modifying the system os.py is not a good idea. A better
work-around is to skip the /dev/urandom fd when you are
closing all fds. This is the code we use:
def close_fd():
# close all inherited file descriptors
start_fd = 3
# Python 2.4.1 and later use /dev/urandom to seed the
random module's RNG
# a file descriptor is kept internally as os._urandomfd
(created on demand
# the first time os.urandom() is called), and should not
be closed
try:
os.urandom(4)
urandom_fd = getattr(os, '_urandomfd', None)
except AttributeError:
urandom_fd = None
if '-close_fd' in sys.argv:
start_fd = int(sys.argv[sys.argv.index('-close_fd') + 1])
for fd in range(start_fd, 256):
if fd == urandom_fd:
continue
try:
os.close(fd)
except OSError:
pass
|
|
Date |
User |
Action |
Args |
2007-08-23 14:30:45 | admin | link | issue1177468 messages |
2007-08-23 14:30:45 | admin | create | |
|