Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use TextReceiveStream as a context manager #299

Merged
merged 1 commit into from
Nov 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions tools/backups2datalad/aioutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,14 @@ async def stream_null_command(
await anyio.open_process(argstrs, cwd=cwd, stderr=None), desc
) as p:
assert p.stdout is not None
async with TextReceiveStream(p.stdout) as stream:
try:
splitter = TerminatedSplitter("\0", retain=False)
async for chunk in splitter.aitersplit(stream):
yield chunk
except BaseException:
log.exception("Exception raised while handling output from %s", desc)
raise
try:
stream = TextReceiveStream(p.stdout)
splitter = TerminatedSplitter("\0", retain=False)
async for chunk in splitter.aitersplit(stream):
yield chunk
except BaseException:
log.exception("Exception raised while handling output from %s", desc)
raise
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does stream need its await stream.aclose() in finally: or at the end of the try block?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it really needs to be called at all. stream.aclose() just closes the underlying stream, which is here p.stdout, but that should be taken care of by the open_process() context manager.

log.log(
logging.DEBUG if p.returncode == 0 else logging.WARNING,
"Command %s exited with return code %d",
Expand Down