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 ?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.087
X-Spam-Evidence '*H*': 0.83; '*S*': 0.00; 'socket': 0.07; 'url:github': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; "wouldn't": 0.14; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'non-blocking': 0.16; 'sockets': 0.16; 'subject:non': 0.16; 'timeout': 0.16; 'url:linux': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; 'written': 0.21; 'feb': 0.22; 'handles': 0.22; 'cc:addr:python.org': 0.22; '2.x': 0.24; 'connected': 0.24; 'fairly': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'header:In-Reply-To:1': 0.27; 'room': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'along': 0.30; 'lines': 0.31; 'that.': 0.31; 'exceptions': 0.31; 'languages': 0.32; 'stuff': 0.32; 'comment': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'data,': 0.36; 'possible': 0.36; 'similar': 0.36; 'being': 0.38; 'server': 0.38; 'generic': 0.38; 'handle': 0.38; 'pm,': 0.38; 'anything': 0.39; 'catch': 0.60; 'new': 0.61; 'matter': 0.61; 'simply': 0.61; 'networking': 0.64; 'more': 0.64; 'here': 0.66; 'listening': 0.74; 'low': 0.83; '"hey,': 0.84; '2015': 0.84; 'asynchronous': 0.84; 'everything,': 0.84; 'pike': 0.84; 'facilities.': 0.91; 'subject:skip:S 20': 0.91; 'system:': 0.91; 'to:none': 0.92; 'clients,': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=qoxle3itwCuZHaez7dGOw6QNGwQMFv1UnVmtSn1ZxC0=; b=KiQ65iLAIMOhGanTwstEm+Jnoh35Dw+O1cvSwPpkR39KYx1o3RI50xkriOLHPZivZI OUqRo0MACBzia/1yey4RE6CNTmYI9Z1T9DLYM6t3TX6KghSRHrHW5m8YsO37OCmsaCTZ FxHvFsCPGvxKbyo+xKozcKvxt8zIVR+RJZWWT7yq2VGAkndjQO6pXHKML7v9dsvL643D L6szWt+bfzkEy2TOLvYtKCSsMjpuznXMyUYoHy1Go7ci79+J40mn700wM6CNCHZRE5dP Ik/Jn+DTAnK3bl7xOicidVmSEADl0awGuDvpytGr0lMRlbPOAuJJKhbowRW41+YthbnJ nfiA==
MIME-Version 1.0
X-Received by 10.50.18.108 with SMTP id v12mr17678489igd.34.1422969691784; Tue, 03 Feb 2015 05:21:31 -0800 (PST)
In-Reply-To <e6d081df-1db0-41a3-905c-e3c2845d5dda@googlegroups.com>
References <mailman.18397.1422871634.18130.python-list@python.org> <47031e69-e94d-4257-8c7d-e7c00a543634@googlegroups.com> <874mr3ibve.fsf@elektro.pacujo.net> <c0e17d52-4978-48fd-8848-30426ea42e14@googlegroups.com> <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 Wed, 4 Feb 2015 00:21:31 +1100
Subject Re: How to write a non blocking SimpleHTTPRequestHandler ?
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.18423.1422971344.18130.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1422971344 news.xs4all.nl 2918 [2001:888:2000:d::a6]:57644
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:85146

Show key headers only | 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