Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 43712:00b136b7da84
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.)
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 30 Oct 2007 17:27:30 +0000 |
| parents | 0067a6ab4854 |
| children | e510b716bd80 |
comparison
equal
deleted
inserted
replaced
| 43708:c34720777cb6 | 43712:00b136b7da84 |
|---|---|
| 718 goto error; | 718 goto error; |
| 719 } | 719 } |
| 720 | 720 |
| 721 /* Set sys.stdin */ | 721 /* Set sys.stdin */ |
| 722 if (!(std = PyFile_FromFd(fileno(stdin), "<stdin>", "r", -1, | 722 if (!(std = PyFile_FromFd(fileno(stdin), "<stdin>", "r", -1, |
| 723 NULL, "\n"))) { | 723 NULL, "\n", 0))) { |
| 724 goto error; | 724 goto error; |
| 725 } | 725 } |
| 726 PySys_SetObject("__stdin__", std); | 726 PySys_SetObject("__stdin__", std); |
| 727 PySys_SetObject("stdin", std); | 727 PySys_SetObject("stdin", std); |
| 728 Py_DECREF(std); | 728 Py_DECREF(std); |
| 729 | 729 |
| 730 /* Set sys.stdout */ | 730 /* Set sys.stdout */ |
| 731 if (!(std = PyFile_FromFd(fileno(stdout), "<stdout>", "w", -1, | 731 if (!(std = PyFile_FromFd(fileno(stdout), "<stdout>", "w", -1, |
| 732 NULL, "\n"))) { | 732 NULL, "\n", 0))) { |
| 733 goto error; | 733 goto error; |
| 734 } | 734 } |
| 735 PySys_SetObject("__stdout__", std); | 735 PySys_SetObject("__stdout__", std); |
| 736 PySys_SetObject("stdout", std); | 736 PySys_SetObject("stdout", std); |
| 737 Py_DECREF(std); | 737 Py_DECREF(std); |
| 738 | 738 |
| 739 /* Set sys.stderr */ | 739 /* Set sys.stderr, replaces the preliminary stderr */ |
| 740 if (!(std = PyFile_FromFd(fileno(stderr), "<stderr>", "w", -1, | 740 if (!(std = PyFile_FromFd(fileno(stderr), "<stderr>", "w", -1, |
| 741 NULL, "\n"))) { | 741 NULL, "\n", 0))) { |
| 742 goto error; | 742 goto error; |
| 743 } | 743 } |
| 744 PySys_SetObject("__stderr__", std); | 744 PySys_SetObject("__stderr__", std); |
| 745 PySys_SetObject("stderr", std); | 745 PySys_SetObject("stderr", std); |
| 746 Py_DECREF(std); | 746 Py_DECREF(std); |
