Skip to content

Conversation

@stefanor
Copy link
Contributor

@stefanor stefanor commented Nov 25, 2025

Writes are not guaranteed to complete by the operating system. Use BufferedWriter to do the necessary retries and raise appropriate errors, if we fail to completely write a .pyc file in one syscall.

@python-cla-bot
Copy link

python-cla-bot bot commented Nov 25, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

Interruption by a system call or something is not completely unexpected.
Retry the write with the remaining data.
@stefanor
Copy link
Contributor Author

Squashed in that suggestion to avoid the CLA bot.

# Raise an OSError so the 'except' below cleans up the partially
# written file.
raise OSError("os.write() didn't write the full pyc file")
with _io.FileIO(fd, 'wb') as file, _io.BufferedWriter(file) as writer:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think just with open(fd, 'wb') as file should work here.

Could technically pass the _os.open as an opener (open(opener=_os.open(...))) but I don't think that actually makes the code simpler/more straightforward

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants