diff options
author | Georg Brandl <georg@python.org> | 2008-01-19 20:22:13 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-01-19 20:22:13 (GMT) |
commit | 309501a61772f4cb72f1004fcbe73964b4130672 (patch) | |
tree | 8737924e043d901d7c62910a97c6aebdd8e62f8e /Modules/posixmodule.c | |
parent | 15ce880cc8c3de29e91e2e867b2db0b19a48e5f3 (diff) | |
download | cpython-309501a61772f4cb72f1004fcbe73964b4130672.zip cpython-309501a61772f4cb72f1004fcbe73964b4130672.tar.gz cpython-309501a61772f4cb72f1004fcbe73964b4130672.tar.bz2 |
#1663329: add os.closerange() to close a range of fds,
ignoring errors, and use this in subprocess to speed up
subprocess creation in close_fds mode. Patch by Mike Klaas.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r-- | Modules/posixmodule.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 696df0d..0038703 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -6156,6 +6156,24 @@ posix_close(PyObject *self, PyObject *args) } +PyDoc_STRVAR(posix_closerange__doc__, +"closerange(fd_low, fd_high)\n\n\ +Closes all file descriptors in [fd_low, fd_high), ignoring errors."); + +static PyObject * +posix_closerange(PyObject *self, PyObject *args) +{ + int fd_from, fd_to, i; + if (!PyArg_ParseTuple(args, "ii:closerange", &fd_from, &fd_to)) + return NULL; + Py_BEGIN_ALLOW_THREADS + for (i = fd_from; i < fd_to; i++) + close(i); + Py_END_ALLOW_THREADS + Py_RETURN_NONE; +} + + PyDoc_STRVAR(posix_dup__doc__, "dup(fd) -> fd2\n\n\ Return a duplicate of a file descriptor."); @@ -8451,6 +8469,7 @@ static PyMethodDef posix_methods[] = { #endif /* HAVE_TCSETPGRP */ {"open", posix_open, METH_VARARGS, posix_open__doc__}, {"close", posix_close, METH_VARARGS, posix_close__doc__}, + {"closerange", posix_closerange, METH_VARARGS, posix_closerange__doc__}, {"dup", posix_dup, METH_VARARGS, posix_dup__doc__}, {"dup2", posix_dup2, METH_VARARGS, posix_dup2__doc__}, {"lseek", posix_lseek, METH_VARARGS, posix_lseek__doc__}, |