Skip to content

Commit

Permalink
Resolve outstanding resource warnings when running tests (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
cottsay authored Dec 3, 2024
1 parent 66ffe9c commit 8fbffef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
22 changes: 9 additions & 13 deletions osrf_pycommon/process_utils/execute_process_nopty.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,14 @@ def yield_to_stream(data, stream):


def _execute_process_nopty(cmd, cwd, env, shell, stderr_to_stdout=True):
if stderr_to_stdout:
p = Popen(cmd,
stdin=PIPE, stdout=PIPE, stderr=STDOUT,
cwd=cwd, env=env, shell=shell, close_fds=False)
else:
p = Popen(cmd,
stdin=PIPE, stdout=PIPE, stderr=PIPE,
cwd=cwd, env=env, shell=shell, close_fds=False)

# Left over data from read which isn't a complete line yet
left_overs = {p.stdout: b'', p.stderr: b''}
stderr = STDOUT if stderr_to_stdout else PIPE
with Popen(
cmd, stdin=PIPE, stdout=PIPE, stderr=stderr,
cwd=cwd, env=env, shell=shell, close_fds=False
) as p:
# Left over data from read which isn't a complete line yet
left_overs = {p.stdout: b'', p.stderr: b''}

fds = list(filter(None, [p.stdout, p.stderr]))
fds = list(filter(None, [p.stdout, p.stderr]))

return _yield_data(p, fds, left_overs, os.linesep)
yield from _yield_data(p, fds, left_overs, os.linesep)
1 change: 1 addition & 0 deletions tests/unit/test_process_utils/impl_aep_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ async def run(cmd, **kwargs):
transport, protocol = await async_execute_process(
create_protocol(), cmd, **kwargs)
retcode = await protocol.complete
transport.close()
return protocol.stdout_buffer, protocol.stderr_buffer, retcode

0 comments on commit 8fbffef

Please sign in to comment.