This uses several helper functions to implement the algorithm suggested by Darek Działak.
this_range.high = fd (no need to create a copy of this_range and is a bit clear, at least for me ;)
this_range.high = fd
this_range
Please avoid creation of set {0..maxfd} as maxfd could be large (it's a smaller problem than closing all fds but still could waste teens miliseconds necessarily)
{0..maxfd}
Please notice also that closerange(a, b) closes [a, b) (thus b is not closed if a != b) I think that corner cases are broken here. Also max_fd is a number of max opened files and first fd is 0 so max closed fd should be max_fd - 1.
closerange(a, b)
[a, b)
b
max_fd
max_fd - 1
as mentioned about ranges for closerange function, expected result here should be: (0, 3), (4, 5), (6, 9)
closerange
(0, 4)
as previously mentioned - need to fix corner cases
Thank you, that helps a lot. (The parameter names to os.closerange do not make that clear.)
os.closerange
I have re-worked this merge request to incorporate the actual behaviour of os.closerange.
rebased onto ad3ac5c47c3107de274ecf2e5e5dd8b83ddacb00
13 new commits added
_get_candidate_file_descriptor_ranges
_close_file_descriptor_ranges
exclude
Pull-Request has been closed by bignose
This uses several helper functions to implement the algorithm suggested by Darek Działak.