select(sock) indicates not-ready, but sock.recv does not block

Nikolaus Rath Nikolaus at
Tue Feb 18 02:29:42 CET 2014

Nikolaus Rath <Nikolaus at> writes:
> Hello,
> I have a problem with using select. I can reliably reproduce a situation
> where,), (), (), 0) returns ((),(),())
> (i.e., no data ready for reading), but an immediately following
> sock.recv() returns data without blocking.

Turns out that I fell into the well-known (except to me) ssl-socket

TL;DR: Relying on select() on an SSL socket is not a good idea because
some internal buffering is done. Better put the socket in non-blocking
mode and try to read something, catching the ssl.Want* exception if
nothing is ready.


Encrypted emails preferred.
PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C

             »Time flies like an arrow, fruit flies like a Banana.«

More information about the Python-list mailing list