Message372337
> So in my local repro, Python is looping forever on successful write() for reasons I'm not immediately sure of.
io.BufferedWriter.write() (well, especially its flush() method) calls write() until all data is written.
Extract of _bufferedwriter_flush_unlocked() code, Modules/_io/buffered.c:
while (self->write_pos < self->write_end) {
n = _bufferedwriter_raw_write(self,
self->buffer + self->write_pos,
Py_SAFE_DOWNCAST(self->write_end - self->write_pos,
Py_off_t, Py_ssize_t));
if (n == -1) {
goto error;
}
else if (n == -2) {
_set_BlockingIOError("write could not complete without blocking",
0);
goto error;
}
self->write_pos += n;
self->raw_pos = self->write_pos;
written += Py_SAFE_DOWNCAST(n, Py_off_t, Py_ssize_t);
/* Partial writes can return successfully when interrupted by a
signal (see write(2)). We must run signal handlers before
blocking another time, possibly indefinitely. */
if (PyErr_CheckSignals() < 0)
goto error;
}
You are correct: if write() returns 0, write() is called again. If write() always returns 0, the loop never stops...
Maybe a BlockingIOError must be raised if write(buffer) returns 0 (and buffer is not empty). |
|
Date |
User |
Action |
Args |
2020-06-25 10:13:15 | vstinner | set | recipients:
+ vstinner, christian.heimes, koobs, kevans |
2020-06-25 10:13:15 | vstinner | set | messageid: <1593079995.43.0.452547607223.issue41013@roundup.psfhosted.org> |
2020-06-25 10:13:15 | vstinner | link | issue41013 messages |
2020-06-25 10:13:15 | vstinner | create | |
|