equal
deleted
inserted
replaced
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 |