How to write a non blocking SimpleHTTPRequestHandler ?

Marko Rauhamaa marko at pacujo.net
Tue Feb 3 08:45:55 EST 2015


Yassine Chaouche <yacinechaouche at yahoo.com>:

> On Tuesday, February 3, 2015 at 12:35:32 PM UTC+1, Marko Rauhamaa wrote:
>> So far I've been happy with select.epoll(), socket.socket() and ten
>> fingers.
>
> [...]
>
> But your comment is interesting because, as I understand it, a
> non-blocking web server is simply a matter of setting timeouts on
> sockets, catch the exceptions and move on.

Now I think you might have some misconceptions about nonblocking
networking I/O. Nonblocking I/O is done using asynchronous, or
event-driven, programming. Your code reacts to external stimuli, never
blocking, mostly just sleeping. The reactions are defined in callback
routings, aka listeners, aka event handlers.

> I don't know why wouldn't that be possible with python stdlib ?

It is possible using the low-level facilities. However, the traditional
high-level facilities are built on multithreading, which (as a rule) is
based on blocking I/O.


Marko



More information about the Python-list mailing list