#11 Re-write `daemon.close_all_open_files` for performance.
Closed by bignose. Opened by bignose.
wip/issue/10/close-open-fds-with-closerange  into  master

Download 11.patch

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 ;)

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)

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.

as mentioned about ranges for closerange function, expected result here should be: (0, 3), (4, 5), (6, 9)

(0, 4)

as previously mentioned - need to fix corner cases

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.

Thank you, that helps a lot. (The parameter names to os.closerange do not make that clear.)

I have re-worked this merge request to incorporate the actual behaviour of os.closerange.

rebased onto ad3ac5c47c3107de274ecf2e5e5dd8b83ddacb00

13 new commits added

  • Remove unused private helper functions.
  • Migrate to _get_candidate_file_descriptor_ranges helper.
  • Migrate to _close_file_descriptor_ranges helper.
  • Implement a helper function to close file descriptors by range.
  • Implement a helper function to get ranges of candidate file descriptors.
  • Iterate over candidate file descriptors to close them.
  • Implement a helper function to get candidate open file descriptors.
  • Use a set for an un-ordered collection of streams.
  • Implement a helper function to get file descriptors of standard streams.
  • Close all non-standard files quickly, when exclude is empty or None.
  • Implement a helper function to close all non-standard files.
  • Extract a separate function to close each file descriptor in turn.
  • Document changes made in this branch.

Pull-Request has been closed by bignose

Metadata