0

I want to patch python popen2 which tries to close all open filehandres by having a loop on [3, SC_OPEN_MAX].

This means that if someone increases the upper limit using ulimit to a huge value like 1,000,000 it will make any python aplication that uses popen to effectevly block.

The who point of the question is: how can you get the list of opened file handler of your process. The solution should work on linux and Windows, at least.

Note: that's for re-fixing http://bugs.python.org/issue1663329

sorin
  • 161,544
  • 178
  • 535
  • 806

1 Answers1

1

Your approach would not work on windows. Actually windows does not even have enumerable file handles. Your for-loop approach was often used in Unix select-poll loops but it fails miserably in Windows because the socket handles were often > 0x80000000.

But also, if I recall correctly, filehandles are closed by default by exec call in linux, and I think something similar would happen in windows. You would have to ask explicitly to get a handle that stays open through exec.

UPDATE:

this might be of interest http://bugs.python.org/issue1663329

Also only now I noticed that you are speaking of popen2 - if the python is new enough you really ought to use subprocess instead