Skip to content

Commit b9bcf74

Browse files
committed
stop using fcntl: not working on windows and line read not blocking posix
[CI SKIP]
1 parent 296956a commit b9bcf74

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

exec_helpers/subprocess_runner.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
from __future__ import absolute_import
2020
from __future__ import unicode_literals
2121

22-
import fcntl
2322
import logging
24-
import os
2523
import select
2624
import sys
2725
import subprocess # nosec # Expected usage
@@ -38,6 +36,7 @@
3836
from exec_helpers import proc_enums
3937

4038
logger = logging.getLogger(__name__)
39+
4140
_win = sys.platform == "win32"
4241
_type_exit_codes = typing.Union[int, proc_enums.ExitCodes]
4342
_type_expected = typing.Optional[typing.Iterable[_type_exit_codes]]
@@ -145,7 +144,7 @@ def poll_streams(
145144
verbose=verbose
146145
)
147146

148-
@threaded.threaded(started=True)
147+
@threaded.threaded(started=True, daemon=True)
149148
def poll_pipes(
150149
proc, # type: subprocess.Popen
151150
result, # type: exec_result.ExecResult
@@ -157,16 +156,6 @@ def poll_pipes(
157156
:type result: exec_result.ExecResult
158157
:type stop: threading.Event
159158
"""
160-
# Get file descriptors for stdout and stderr streams
161-
fd_stdout = proc.stdout.fileno()
162-
fd_stderr = proc.stderr.fileno()
163-
# Get flags of stdout and stderr streams
164-
fl_stdout = fcntl.fcntl(fd_stdout, fcntl.F_GETFL)
165-
fl_stderr = fcntl.fcntl(fd_stderr, fcntl.F_GETFL)
166-
# Set nonblock mode for stdout and stderr streams
167-
fcntl.fcntl(fd_stdout, fcntl.F_SETFL, fl_stdout | os.O_NONBLOCK)
168-
fcntl.fcntl(fd_stderr, fcntl.F_SETFL, fl_stderr | os.O_NONBLOCK)
169-
170159
while not stop.isSet():
171160
time.sleep(0.1)
172161
poll_streams(

test/test_subprocess_runner.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def fileno(self):
5151

5252
@mock.patch('exec_helpers.subprocess_runner.logger', autospec=True)
5353
@mock.patch('select.select', autospec=True)
54-
@mock.patch('fcntl.fcntl', autospec=True)
5554
@mock.patch('subprocess.Popen', autospec=True, name='subprocess.Popen')
5655
class TestSubprocessRunner(unittest.TestCase):
5756
@staticmethod
@@ -84,7 +83,7 @@ def gen_cmd_result_log_message(result):
8483
return (u"Command exit code '{code!s}':\n{cmd!s}\n"
8584
.format(cmd=result.cmd.rstrip(), code=result.exit_code))
8685

87-
def test_call(self, popen, fcntl, select, logger):
86+
def test_call(self, popen, select, logger):
8887
popen_obj, exp_result = self.prepare_close(popen)
8988
select.return_value = [popen_obj.stdout, popen_obj.stderr], [], []
9089

@@ -130,7 +129,7 @@ def test_call(self, popen, fcntl, select, logger):
130129
mock.call.poll(), popen_obj.mock_calls
131130
)
132131

133-
def test_call_verbose(self, popen, fcntl, select, logger):
132+
def test_call_verbose(self, popen, select, logger):
134133
popen_obj, _ = self.prepare_close(popen)
135134
select.return_value = [popen_obj.stdout, popen_obj.stderr], [], []
136135

0 commit comments

Comments
 (0)