Richard Oudkerk added the comment:
On 03/06/2013 3:07pm, spresse1 wrote:
> I could reimplement the close_all_fds_except() call (in straight python, using
> os.closerange()). That seems like a reasonable solution, if a bit of a hack.
> However, given that pipes are exposed by multiprocessing, it might make sense
> to try to get this function incorperated into the main version of it?
close_all_fds_except() is already pure python:
try:
MAXFD = os.sysconf("SC_OPEN_MAX")
except:
MAXFD = 256
def close_all_fds_except(fds):
fds = list(fds) + [-1, MAXFD]
fds.sort()
for i in range(len(fds) - 1):
os.closerange(fds[i]+1, fds[i+1])
> I also think that with introspection it would be possible for the
> subprocessing
> module to be aware of which file descriptors are still actively referenced.
> (ie: 0,1,2 always referenced, introspect through objects in the child to see
> if
> they have the file.fileno() method) However, I can't state this as a certainty
> without going off and actually implementing such a version. Additionally, I
> can
> make absolutely no promises as to the speed of this. Perhaps, if it
> functioned,
> it would be an option one could turn on for cases like mine.
So you want a way to visit all objects directly or indirectly referenced
by the process object, so you can check whether they have a fileno()
method? At the C level all object types which support GC define a
tp_traverse function, so maybe that could be made available from pure
Python.
But really, this sounds rather fragile.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue18120>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com