[Tutor] Issue with wsgi_ref.simple_server - sometimes very slow!

Attila Szabó szattila88 at gmail.com
Wed May 31 14:44:48 EDT 2017

Hi All,

I'm facing a really strange behavior with python's wsgi_ref.simple_server

I have the following setup:
- Raspberry Pi 2
- Ubuntu Mate 16.04
- Python3.5

I have the following simple source:

#!/usr/bin/env python3import wsgiref.simple_server
def my_func(env, start_response):
  start_response('200 OK', [])
  return [''.encode()]

server = wsgiref.simple_server.make_server(


After several requests (around every ~5 requests) the response time is
getting really-really slow (1-60sec) compared to the average 0.1s response,
the server serves the request and then quick again for couple of new
requests and then again....getting to be slow...

I'm trying to reach the node via my router, and also from outside internet
and the latency is there.

I have tried the same code also on Windows10 with same python version, from
behind the same router and the issue was not present.
Also I have removed the router and connected internet directly to Raspberry
PI and I faced the same issue.
So I think I can say that that is not because of the router for sure.

Also, always when I interrupt the running server I'm getting the following

Exception happened during processing of request from ('',
3540)Traceback (most recent call last):
  File "/usr/lib/python3.5/socketserver.py", line 313, in
    self.process_request(request, client_address)
  File "/usr/lib/python3.5/socketserver.py", line 341, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.5/socketserver.py", line 354, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.5/socketserver.py", line 681, in __init__
  File "/usr/lib/python3.5/wsgiref/simple_server.py", line 119, in handle
    self.raw_requestline = self.rfile.readline(65537)
  File "/usr/lib/python3.5/socket.py", line 575, in readinto
    return self._sock.recv_into(b)KeyboardInterrupt

That's why I think there is some issue with that recv_into function, but I
cannot figure it out how to resolve this... :/

Does anybody faced this same issue? Or anybody has an idea what should I
try or what should I modify in python source to solve this issue?


More information about the Tutor mailing list