Commit d1ae68aa authored by Denis Bilenko's avatar Denis Bilenko

pywsgi: react to any error in accept() by sleeping a bit

parent 9514e594
......@@ -386,19 +386,19 @@ def server(sock, site, log=None, environ=None, max_size=None, max_http_version=D
port = ''
print "(%s) wsgi starting up on %s://%s%s/" % (os.getpid(), scheme, host, port)
delay = 0.1
while True:
try:
client_socket = sock.accept()
delay = 0.1
pool.spawn(serv.process_request, client_socket)
except socket.error, e:
if e[0] == errno.EMFILE:
# we ran out of file descriptors and will call accept in a busy loop...
# ...which we avoid by sleeping a bit
print "WARNING: pywsgi: out of file descriptors. cannot accept outstanding connections."
sleep(1.0)
continue
if e[0] != errno.EPIPE and e[0] != errno.EBADF:
raise
print "WARNING: pywsgi: out of file descriptors; will not accept for %s seconds" % delay
else:
print 'WARNING: pywsgi: accept failed with error %s: %s; will not accept for %s seconds' % (e[0], e, delay)
sleep(delay)
delay *= 2
finally:
try:
sock.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment