This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients alexey-smirnov, amaury.forgeotdarc, georg.brandl, neologix, petri.lehtinen, pitrou, python-dev, socketpair, vstinner
Date 2011-05-23.11:50:56
SpamBayes Score 4.704659e-11
Marked as misclassified No
Message-id <1306151457.43.0.770422598622.issue12105@psf.upfronthosting.co.za>
In-reply-to
Content
Another idea is to write a best-effort function to open a file with CLOEXEC flag:
 * use O_CLOEXEC if available
 * use fcntl(fd, F_SETFD, flags | FD_CLOEXEC) if O_CLOEXEC is missing or was silently ignored by the kernel (by open)

Attached open_cloexec.py is an implementation.

--

Usage of "CLOEXEC" in the Python standard library:

- subprocess: create pipe. use pipe2() or pipe()+fcntl(FD_CLOEXEC)
- test_socket: create a socket. use SOCK_CLOEXEC. The test is skipped if the kernel is Linux < 2.6.28. It has a nice linux_version() which should be moved to the platform module.
- test_posix: check open(O_CLOEXEC).
- test_tempfile: test "cloexec" behaviour using os.spawnl()
- xmlrpclib: use FD_CLOEXEC on the socket

You may also add pipe_cloexec() to os, and socket_cloexec() to socket?
History
Date User Action Args
2011-05-23 11:50:57vstinnersetrecipients: + vstinner, georg.brandl, amaury.forgeotdarc, pitrou, neologix, socketpair, python-dev, petri.lehtinen, alexey-smirnov
2011-05-23 11:50:57vstinnersetmessageid: <1306151457.43.0.770422598622.issue12105@psf.upfronthosting.co.za>
2011-05-23 11:50:56vstinnerlinkissue12105 messages
2011-05-23 11:50:56vstinnercreate