Message136615
| 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? |
|