Victor Stinner  committed ab990f2

pep cloexec

  • Participants
  • Parent commits c61b891
  • Branches default

Comments (0)

Files changed (1)

File python/pep_cloexec.rst

 Closing the file descriptor in the parent process doesn't close the related
 resource (file, socket, ...) because it is still open in the child process.
-For example, the listening socket of TCPServer is not closed on ``exec()``: the
+The listening socket of TCPServer is not closed on ``exec()``: the
 child process is able to get connection from new clients; if the parent closes
 the socket and create a new listening socket on the same address, it would
 get an "address already is used" error.
+Not closing file descriptors can lead to resource exhausion: even if the parent
+closes all files, creating a new file descriptor may fail with "too many files"
+because files are still open because they are shared with the child process
+(which did not close them).
  * ``xmlrpc.server``
  * Maybe: ``signal``, ``threading``
+ * ``subprocess.Popen`` constructor has an ``pass_fds`` argument to specify
+   which file descriptors must be inherited. The close-on-exec flag of these
+   file descriptors must be changed if ``sys.getdefaultcloexec()`` is ``True``.
  * `Support accept4() for atomic setting of flags at socket creation
+ * `Add an 'afterfork' module
+   <>`_