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


Groups > comp.lang.python > #85146

Re: How to write a non blocking SimpleHTTPRequestHandler ?

References (4 earlier) <mailman.18420.1422960897.18130.python-list@python.org> <b6cb0fcb-9934-41b6-a8f6-902d26f2588c@googlegroups.com> <mailman.18421.1422961678.18130.python-list@python.org> <87r3u7grd3.fsf@elektro.pacujo.net> <e6d081df-1db0-41a3-905c-e3c2845d5dda@googlegroups.com>
Date 2015-02-04 00:21 +1100
Subject Re: How to write a non blocking SimpleHTTPRequestHandler ?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.18423.1422971344.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Feb 3, 2015 at 11:56 PM, Yassine Chaouche
<yacinechaouche@yahoo.com.dmarc.invalid> wrote:
> 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. I don't know why wouldn't that be possible with python stdlib ?
>

Not really. You could, in theory, set very low timeouts and then poll
everything, but it's not efficient. What you want to do is say to the
system "Hey, see all these sockets? Let me know when *any one of them*
has stuff for me", where "stuff" would be a new connected client if
it's a listening socket, or some data written if it's a connected
socket; and you might need to check if there's room to write more
data, too, which you can do with the same syscall.

The key here is that you have a long timeout on the meta-event "any
one of these being ready". That's not simply a matter of setting
socket timeouts; you need a way to handle the meta-event, and that's
something along the lines of select():

http://linux.die.net/man/2/select

Other languages have inbuilt asynchronous I/O handlers; eg Pike
handles this fairly well, and I've made some use of it with a generic
networking system:

https://github.com/Rosuav/Hogan

Basically, you spin up a server with any number of listening sockets,
each of which can talk to any number of connected clients, and all of
those sockets get smoothly multiplexed on a single thread. Lots of
other languages have similar facilities. Python 2.x doesn't have
anything of that nature; Python 3's asyncio is exactly that.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: How to write a non blocking SimpleHTTPRequestHandler ? Amirouche Boubekki <amirouche.boubekki@gmail.com> - 2015-02-02 10:07 +0000
  Re: How to write a non blocking SimpleHTTPRequestHandler ? Yassine Chaouche <yacinechaouche@yahoo.com> - 2015-02-03 01:08 -0800
    Re: How to write a non blocking SimpleHTTPRequestHandler ? Marko Rauhamaa <marko@pacujo.net> - 2015-02-03 11:27 +0200
      Re: How to write a non blocking SimpleHTTPRequestHandler ? Yassine Chaouche <yacinechaouche@yahoo.com> - 2015-02-03 02:47 -0800
        Re: How to write a non blocking SimpleHTTPRequestHandler ? Chris Angelico <rosuav@gmail.com> - 2015-02-03 21:54 +1100
          Re: How to write a non blocking SimpleHTTPRequestHandler ? Yassine Chaouche <yacinechaouche@yahoo.com> - 2015-02-03 03:04 -0800
            Re: How to write a non blocking SimpleHTTPRequestHandler ? Chris Angelico <rosuav@gmail.com> - 2015-02-03 22:07 +1100
              Re: How to write a non blocking SimpleHTTPRequestHandler ? Yassine Chaouche <yacinechaouche@yahoo.com> - 2015-02-03 03:23 -0800
              Re: How to write a non blocking SimpleHTTPRequestHandler ? Marko Rauhamaa <marko@pacujo.net> - 2015-02-03 13:35 +0200
                Re: How to write a non blocking SimpleHTTPRequestHandler ? Yassine Chaouche <yacinechaouche@yahoo.com> - 2015-02-03 04:56 -0800
                Re: How to write a non blocking SimpleHTTPRequestHandler ? Marko Rauhamaa <marko@pacujo.net> - 2015-02-03 15:45 +0200
                Re: How to write a non blocking SimpleHTTPRequestHandler ? Chris Angelico <rosuav@gmail.com> - 2015-02-04 01:03 +1100
                Re: How to write a non blocking SimpleHTTPRequestHandler ? Marko Rauhamaa <marko@pacujo.net> - 2015-02-03 16:20 +0200
                Re: How to write a non blocking SimpleHTTPRequestHandler ? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-02-03 20:25 -0500
                Re: How to write a non blocking SimpleHTTPRequestHandler ? Chris Angelico <rosuav@gmail.com> - 2015-02-04 00:21 +1100
                Re: How to write a non blocking SimpleHTTPRequestHandler ? Amirouche Boubekki <amirouche.boubekki@gmail.com> - 2015-02-03 14:09 +0000
                Re: How to write a non blocking SimpleHTTPRequestHandler ? Yassine Chaouche <yacinechaouche@yahoo.com> - 2015-02-03 06:50 -0800
                Re: How to write a non blocking SimpleHTTPRequestHandler ? Filadelfo Fiamma <philosganga@gmail.com> - 2015-02-03 16:03 +0100
                Re: How to write a non blocking SimpleHTTPRequestHandler ? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-02-03 16:39 +0000
                Re: How to write a non blocking SimpleHTTPRequestHandler ? Yassine Chaouche <yacinechaouche@yahoo.com> - 2015-02-08 06:13 -0800
            Re: How to write a non blocking SimpleHTTPRequestHandler ? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-02-03 12:10 +0000

csiph-web