Commit 35f061c7 authored by Vincent Pelletier's avatar Vincent Pelletier

http: Catch an occasional error not handled in standard library.

parent 9e773253
......@@ -22,6 +22,7 @@ from __future__ import absolute_import, print_function
import argparse
from collections import defaultdict
import datetime
import errno
from getpass import getpass
import glob
import itertools
......@@ -95,6 +96,40 @@ class ThreadingWSGIServer(ThreadingMixIn, WSGIServer):
self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
WSGIServer.server_bind(self)
# pylint: disable=arguments-differ
def serve_forever(self, *args, **kw):
"""
Handle one request at a time until shutdown.
In addition to python's version:
- intercept EBADF on shutdown if select is interrupted:
"""
try:
return WSGIServer.serve_forever(self, *args, **kw)
except socket.error as exception:
# Workaround for the following unhandled error:
# Traceback (most recent call last):
# File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
# self.run()
# File "/usr/lib/python2.7/threading.py", line 754, in run
# self.__target(*self.__args, **self.__kwargs)
# File "/usr/lib/python2.7/SocketServer.py", line 231, in serve_forever
# poll_interval)
# File "/usr/lib/python2.7/SocketServer.py", line 150, in _eintr_retry
# return func(*args)
# File "/usr/lib/python2.7/SocketServer.py", line 459, in fileno
# return self.socket.fileno()
# File "/usr/lib/python2.7/socket.py", line 228, in meth
# return getattr(self._sock,name)(*args)
# File "/usr/lib/python2.7/socket.py", line 174, in _dummy
# raise error(EBADF, 'Bad file descriptor')
# error: [Errno 9] Bad file descriptor
# Sadly, self.__shutdown_request is not accessible from here, so do not
# check any further.
if exception.errno != errno.EBADF:
raise
# pylint: enable=arguments-differ
def _buildQuoteCharList():
# All chars considered guilty
result = ['\\x%02x' % x for x in xrange(256)]
......
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