Skip to content

Instantly share code, notes, and snippets.

@coldmind
Created April 5, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coldmind/a45879b0e4941336b24e to your computer and use it in GitHub Desktop.
Save coldmind/a45879b0e4941336b24e to your computer and use it in GitHub Desktop.
socket read timeout in django request
diff --git a/django/core/handlers/wsgi.py b/django/core/handlers/wsgi.py
index 50766cb..b133310 100644
--- a/django/core/handlers/wsgi.py
+++ b/django/core/handlers/wsgi.py
@@ -38,9 +38,14 @@ class LimitedStream(object):
size = self.remaining
if size == 0:
return b''
- result = self.stream.read(size)
- self.remaining -= len(result)
- return result
+ self.stream._sock.settimeout(10)
+ try:
+ result = self.stream.read(size)
+ except http.UnreadablePostError:
+ raise Exception('Some exception')
+ else:
+ self.remaining -= len(result)
+ return result
def read(self, size=None):
if size is None:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment