Mercurial > public > mercurial-scm > hg
comparison tests/test-stdio.py @ 49296:b6b6ae9ea91e
py3: remove dead code to make file descriptors non-inheritable
On Python 3, file descriptors are already non-inheritable by default.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Sun, 29 May 2022 15:43:21 +0200 |
parents | 6000f5b25c9b |
children | 402f9f0f9387 |
comparison
equal
deleted
inserted
replaced
49295:7d9a45c7517f | 49296:b6b6ae9ea91e |
---|---|
12 import sys | 12 import sys |
13 import tempfile | 13 import tempfile |
14 import unittest | 14 import unittest |
15 | 15 |
16 from mercurial import pycompat, util | 16 from mercurial import pycompat, util |
17 | |
18 | |
19 if pycompat.ispy3: | |
20 | |
21 def set_noninheritable(fd): | |
22 # On Python 3, file descriptors are non-inheritable by default. | |
23 pass | |
24 | |
25 | |
26 else: | |
27 if pycompat.iswindows: | |
28 # unused | |
29 set_noninheritable = None | |
30 else: | |
31 import fcntl | |
32 | |
33 def set_noninheritable(fd): | |
34 old = fcntl.fcntl(fd, fcntl.F_GETFD) | |
35 fcntl.fcntl(fd, fcntl.F_SETFD, old | fcntl.FD_CLOEXEC) | |
36 | 17 |
37 | 18 |
38 TEST_BUFFERING_CHILD_SCRIPT = r''' | 19 TEST_BUFFERING_CHILD_SCRIPT = r''' |
39 import os | 20 import os |
40 | 21 |
125 | 106 |
126 | 107 |
127 @contextlib.contextmanager | 108 @contextlib.contextmanager |
128 def _pipes(): | 109 def _pipes(): |
129 rwpair = os.pipe() | 110 rwpair = os.pipe() |
130 # Pipes are already non-inheritable on Windows. | |
131 if not pycompat.iswindows: | |
132 set_noninheritable(rwpair[0]) | |
133 set_noninheritable(rwpair[1]) | |
134 with _closing(rwpair): | 111 with _closing(rwpair): |
135 yield rwpair | 112 yield rwpair |
136 | 113 |
137 | 114 |
138 @contextlib.contextmanager | 115 @contextlib.contextmanager |
141 raise unittest.SkipTest("PTYs are not supported on Windows") | 118 raise unittest.SkipTest("PTYs are not supported on Windows") |
142 import pty | 119 import pty |
143 import tty | 120 import tty |
144 | 121 |
145 rwpair = pty.openpty() | 122 rwpair = pty.openpty() |
146 set_noninheritable(rwpair[0]) | |
147 set_noninheritable(rwpair[1]) | |
148 with _closing(rwpair): | 123 with _closing(rwpair): |
149 tty.setraw(rwpair[0]) | 124 tty.setraw(rwpair[0]) |
150 yield rwpair | 125 yield rwpair |
151 | 126 |
152 | 127 |