Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66628 > unrolled thread

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

Started byNikolaus Rath <Nikolaus@rath.org>
First post2014-02-17 17:29 -0800
Last post2014-02-17 17:29 -0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: select(sock) indicates not-ready, but sock.recv does not block Nikolaus Rath <Nikolaus@rath.org> - 2014-02-17 17:29 -0800

#66628 — Re: select(sock) indicates not-ready, but sock.recv does not block

FromNikolaus Rath <Nikolaus@rath.org>
Date2014-02-17 17:29 -0800
SubjectRe: select(sock) indicates not-ready, but sock.recv does not block
Message-ID<mailman.7112.1392686986.18130.python-list@python.org>
Nikolaus Rath <Nikolaus@rath.org> writes:
> Hello,
>
> I have a problem with using select. I can reliably reproduce a situation
> where select.select((sock.fileno(),), (), (), 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
trap: http://docs.python.org/3/library/ssl.html#notes-on-non-blocking-sockets

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.

Best,
-Nikolaus

-- 
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.«

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web