diff options
author | Guido van Rossum <guido@python.org> | 2007-10-30 17:27:30 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-10-30 17:27:30 +0000 |
commit | 2dced8b602df10531cab6cd87da5503c06f14888 (patch) | |
tree | bf87d57eb4945b66b672aadfb87c071449391441 /Python | |
parent | 2673a5723433ff398fed901a8ebebb265031091e (diff) | |
download | cpython-git-2dced8b602df10531cab6cd87da5503c06f14888.tar.gz |
Patch 1329 (partial) by Christian Heimes.
Add a closefd flag to open() which can be set to False to prevent closing
the file descriptor when close() is called or when the object is destroyed.
Useful to ensure that sys.std{in,out,err} keep their file descriptors open
when Python is uninitialized. (This was always a feature in 2.x, it just
wasn't implemented in 3.0 yet.)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/import.c | 2 | ||||
-rw-r--r-- | Python/pythonrun.c | 8 |
2 files changed, 5 insertions, 5 deletions
diff --git a/Python/import.c b/Python/import.c index 24935547e6..be456f1b50 100644 --- a/Python/import.c +++ b/Python/import.c @@ -2588,7 +2588,7 @@ call_find_module(char *name, PyObject *path) (char*)PyUnicode_GetDefaultEncoding(); } fob = PyFile_FromFd(fd, pathname, fdp->mode, -1, - (char*)encoding, NULL); + (char*)encoding, NULL, 1); if (fob == NULL) { close(fd); PyMem_FREE(found_encoding); diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 330667a219..76da8fb7f7 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -720,7 +720,7 @@ initstdio(void) /* Set sys.stdin */ if (!(std = PyFile_FromFd(fileno(stdin), "<stdin>", "r", -1, - NULL, "\n"))) { + NULL, "\n", 0))) { goto error; } PySys_SetObject("__stdin__", std); @@ -729,16 +729,16 @@ initstdio(void) /* Set sys.stdout */ if (!(std = PyFile_FromFd(fileno(stdout), "<stdout>", "w", -1, - NULL, "\n"))) { + NULL, "\n", 0))) { goto error; } PySys_SetObject("__stdout__", std); PySys_SetObject("stdout", std); Py_DECREF(std); - /* Set sys.stderr */ + /* Set sys.stderr, replaces the preliminary stderr */ if (!(std = PyFile_FromFd(fileno(stderr), "<stderr>", "w", -1, - NULL, "\n"))) { + NULL, "\n", 0))) { goto error; } PySys_SetObject("__stderr__", std); |