Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85070
| From | Amirouche Boubekki <amirouche.boubekki@gmail.com> |
|---|---|
| Date | 2015-02-02 10:07 +0000 |
| Subject | Re: How to write a non blocking SimpleHTTPRequestHandler ? |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18397.1422871634.18130.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
On Mon Feb 02 2015 at 10:55:26 AM <yacinechaouche@yahoo.com.dmarc.invalid>
wrote:
> I wrote a little script that acts like a proxy, you just give it a URL and
> it will fetch the content and display it back to you.
>
> For some reason, this proxy blocks sometimes and refuses to serve any new
> queries. The script still runs, but it seems like it's stuck somewhere.
>
> When I strace it to see what it's doing, I find it hanging on this
> instruction :
> root@backup[10.10.10.21] ~/SCRIPTS/INFOMANIAK # strace -fp 6918
> Process 6918 attached - interrupt to quit
> recvfrom(6,
> ^CProcess 6918 detached
> root@backup[10.10.10.21] ~/SCRIPTS/INFOMANIAK #
>
> I read in the SimpleHTTPServer source code that one can inherit from the
> SocketServer.TrheadingMixIn mixin to enable a threaded server to handle
> multiple requests at a time instead of just one (thinking maybe that's what
> was blocking it). However, it seems like it has nothing to do with my
> problem. What I need to do is not only handle multiple requests at a time,
> but more importantly to make the request handler non-blocking.
>
> Any ideas ? here's come code :
>
> import SimpleHTTPServer
> import BaseHTTPServer
> import SocketServer
> import requests
>
> class Handler(SocketServer.ThreadingMixIn,SimpleHTTPServer.SimpleH
> TTPRequestHandler):
> def do_GET(self):
> self.send_response(200)
> self.send_header('Content-Type', 'text/html')
> self.end_headers()
> # self.path will contain a URL to be fetched by my proxy
> self.wfile.write(getFlux(self.path.lstrip("/")))
>
> session = requests.Session()
> IP,PORT = "MY_IP_HERE",8080
>
> def getFlux(url):
> response = session.get(url)
> s = response.text
> return s
>
> server = BaseHTTPServer.HTTPServer((IP,PORT),Handler)
> server.serve_forever()
>
Your code seem perfectly fine. I had some trouble with py3's http.server
with IE10 (in a virtualbox...), I put together a small server script
similar to http.server that doesn't hang up on microsoft. It works with
ayncio. It's not ready to serve big files, but hopefully you can fix that.
HTH
> Thank you.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll 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