Created
September 7, 2012 23:29
-
-
Save ThiefMaster/3670723 to your computer and use it in GitHub Desktop.
SSL fix for flask dev server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from SocketServer import TCPServer | |
from OpenSSL import SSL | |
def patch_shutdown_request(): | |
# Fix SocketServer's shutdown not working with pyopenssl | |
def my_shutdown_request(self, request): | |
"""Called to shutdown and close an individual request.""" | |
try: | |
#explicitly shutdown. socket.close() merely releases | |
#the socket and waits for GC to perform the actual close. | |
try: | |
request.shutdown(socket.SHUT_WR) | |
except TypeError: | |
# ssl sockets don't support an argument | |
try: | |
request.shutdown() | |
except SSL.Error: | |
pass | |
except socket.error: | |
pass # some platforms may raise ENOTCONN here | |
self.close_request(request) | |
TCPServer.shutdown_request = my_shutdown_request |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This looks like it'll solve a problem I'm having, but Google hasn't helped me figure out how to APPLY this fix. Forgive me, I'm a sysadmin not a web dev so I'm mostly hacking at a Flask app written by someone else.
Where should I put a call to patch_shutdown_request()? Sometime before app.run()?