gh-149474: use Py_fopen in Binary{Reader,Writer} for audit hook and path-like support#149524
gh-149474: use Py_fopen in Binary{Reader,Writer} for audit hook and path-like support#149524pablogsal merged 4 commits intopython:mainfrom
Py_fopen in Binary{Reader,Writer} for audit hook and path-like support#149524Conversation
|
cc @ZeroIntensity @sobolevn (you +1 my comment) |
| /* Add file descriptor-level hints for better kernel I/O scheduling */ | ||
| #if defined(__linux__) && defined(POSIX_FADV_SEQUENTIAL) | ||
| (void)posix_fadvise(reader->fd, 0, 0, POSIX_FADV_SEQUENTIAL); | ||
| (void)posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); |
There was a problem hiding this comment.
Question: os_posix_fadvise_impl has two implementation details that this place does not: Py_BEGIN_ALLOW_THREADS is set and async_err = PyErr_CheckSignals() is checked.
Do we need to do this here?
There was a problem hiding this comment.
I don’t think we need it here. These calls are best-effort performance hints and intentionally ignore all posix_fadvise() failures, unlike os.posix_fadvise where the result is user-visible and must handle EINTR/signals correctly. PyErr_CheckSignals() would make an advisory hint observable by turning some interruptions into failures, which does not match the surrounding madvise()/posix_fadvise() handling.
y_BEGIN_ALLOW_THREADS also is not needed for correctness here; if we wanted to tune this path, we would probably need to look at the whole block, since mmap(... MAP_POPULATE) and madvise(... MADV_WILLNEED) are also currently called with the GIL held.
|
|
||
| if (writer->fp) { | ||
| fclose(writer->fp); | ||
| Py_fclose(writer->fp); |
There was a problem hiding this comment.
question: why don't we check the return code here? Because the returned type is void?
There was a problem hiding this comment.
There is nothing we can do if close fails, we could log perhaps...
There was a problem hiding this comment.
In this case I woudl suggest that we explicitly suppress the returned value and add a comment. We can also raise an unraisable exception (which I do in curses)
|
Thanks @maurycy for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
GH-149586 is a backport of this pull request to the 3.15 branch. |
As a bonus: PEP 446... so that's a hat-trick: 519 + 578 + 446!
Closes #149474