Python - non-blocking socket operations raise BlockingIOError
bostonrwalker opened this issue · comments
Calling connect()
on a non-blocking socket always raises BlockingIOError
, due to the C API call returning ZTS_EINPROGRESS
.
Example:
socket.settimeout(60.)
socket.connect(("12.34.56.78", 5678))
> BlockingIOError
When using asynchronous (non-blocking) sockets, EINPROGRESS
means that the operation is started and to check back again later before continuing to perform operations on the socket.
As well, calling recv()
on a non-blocking socket raises ZTS_EGAIN
.
In the Python implementations of connect()
, recv()
, and other functions, asynchronous operations are blocked on by calling poll()
or select()
on the socket before returning (see socketmodule.c#L816). So the correct behaviour, at least for the Python bindings, should be:
- Call
zts_bsd_connect()
(or other operation) and get an error code - If the error code is
EINPROGRESS
,EAGAIN
, orEALREADY
,select()
orpoll()
the socket until the socket is ready for the next operation - Return no error