python/cpython · error · RuntimeError
unable to write; sendfile is in progress
Error message
unable to write; sendfile is in progress
What it means
Error "unable to write; sendfile is in progress" thrown in python/cpython.
Source
Thrown at Lib/asyncio/proactor_events.py:343
if length > -1:
self._data_received(data, length)
class _ProactorBaseWritePipeTransport(_ProactorBasePipeTransport,
transports.WriteTransport):
"""Transport for write pipes."""
_start_tls_compatible = True
def write(self, data):
if not isinstance(data, (bytes, bytearray, memoryview)):
raise TypeError(
f"data argument must be a bytes-like object, "
f"not {type(data).__name__}")
if self._eof_written:
raise RuntimeError('write_eof() already called')
if self._empty_waiter is not None:
raise RuntimeError('unable to write; sendfile is in progress')
if not data:
return
if self._conn_lost:
if self._conn_lost >= constants.LOG_THRESHOLD_FOR_CONNLOST_WRITES:
logger.warning('socket.send() raised exception.')
self._conn_lost += 1
return
# Observable states:
# 1. IDLE: _write_fut and _buffer both None
# 2. WRITING: _write_fut set; _buffer None
# 3. BACKED UP: _write_fut set; _buffer a bytearray
# We always copy the data, so the caller can't modify it
# while we're still waiting for the I/O to happen.
if self._write_fut is None: # IDLE -> WRITING
assert self._buffer is NoneView on GitHub (pinned to bc6749cc3b)
Solutions
- Wait for the sendfile operation to finish before writing; chain the write after the sendfile future completes.
- Do not interleave transport.write() with loop.sendfile() on the same transport.
When it happens
Trigger: Raised when write() is attempted while a sendfile operation is in progress on the transport.
Common situations: See trigger scenarios.
AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14).
Data as JSON: /api/errors/8559f12dd0c2db18.
Report an issue: GitHub.