Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #16099 -- Enabled threading for the runserver management comman…

…d and added a --nothreading option to disable it if needed. This should help Google Chrome users because it opens more than one connection speculatively.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16427 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit ce165f7bbf0c481a20db6b4b9f764b8bb89348ba 1 parent 838a16e
Jannis Leidel authored June 17, 2011
7  django/core/management/commands/runserver.py
@@ -17,10 +17,13 @@
17 17
 ):)?(?P<port>\d+)$""", re.X)
18 18
 DEFAULT_PORT = "8000"
19 19
 
  20
+
20 21
 class BaseRunserverCommand(BaseCommand):
21 22
     option_list = BaseCommand.option_list + (
22 23
         make_option('--ipv6', '-6', action='store_true', dest='use_ipv6', default=False,
23 24
             help='Tells Django to use a IPv6 address.'),
  25
+        make_option('--nothreading', action='store_false', dest='use_threading', default=True,
  26
+            help='Use threading for web server.'),
24 27
         make_option('--noreload', action='store_false', dest='use_reloader', default=True,
25 28
             help='Tells Django to NOT use the auto-reloader.'),
26 29
     )
@@ -81,6 +84,7 @@ def inner_run(self, *args, **options):
81 84
         from django.conf import settings
82 85
         from django.utils import translation
83 86
 
  87
+        threading = options.get('use_threading', False)
84 88
         shutdown_message = options.get('shutdown_message', '')
85 89
         quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'
86 90
 
@@ -104,7 +108,8 @@ def inner_run(self, *args, **options):
104 108
 
105 109
         try:
106 110
             handler = self.get_handler(*args, **options)
107  
-            run(self.addr, int(self.port), handler, ipv6=self.use_ipv6)
  111
+            run(self.addr, int(self.port), handler,
  112
+                ipv6=self.use_ipv6, threading=threading)
108 113
         except WSGIServerException, e:
109 114
             # Use helpful error messages instead of ugly tracebacks.
110 115
             ERRORS = {
9  django/core/servers/basehttp.py
@@ -12,6 +12,7 @@
12 12
 import sys
13 13
 import traceback
14 14
 import urllib
  15
+from SocketServer import ThreadingMixIn
15 16
 from wsgiref import simple_server
16 17
 from wsgiref.util import FileWrapper   # for backwards compatibility
17 18
 
@@ -205,8 +206,12 @@ def _should_handle(self, path):
205 206
         return path.startswith(self.base_url[2]) and not self.base_url[1]
206 207
 
207 208
 
208  
-def run(addr, port, wsgi_handler, ipv6=False):
  209
+def run(addr, port, wsgi_handler, ipv6=False, threading=False):
209 210
     server_address = (addr, port)
210  
-    httpd = WSGIServer(server_address, WSGIRequestHandler, ipv6=ipv6)
  211
+    if threading:
  212
+        httpd_cls = type('WSGIServer', (ThreadingMixIn, WSGIServer), {})
  213
+    else:
  214
+        httpd_cls = WSGIServer
  215
+    httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
211 216
     httpd.set_app(wsgi_handler)
212 217
     httpd.serve_forever()
5  docs/man/django-admin.1
@@ -75,7 +75,7 @@ Runs this project as a FastCGI application. Requires flup. Use
75 75
 .B runfcgi help
76 76
 for help on the KEY=val pairs.
77 77
 .TP
78  
-.BI "runserver [" "\-\-noreload" "] [" "\-\-nostatic" "] [" "\-\-insecure" "] [" "\-\-ipv6" "] [" "\-\-adminmedia=ADMIN_MEDIA_PATH" "] [" "port|ipaddr:port" "]"
  78
+.BI "runserver [" "\-\-noreload" "] [" "\-\-nothreading" "] [" "\-\-nostatic" "] [" "\-\-insecure" "] [" "\-\-ipv6" "] [" "\-\-adminmedia=ADMIN_MEDIA_PATH" "] [" "port|ipaddr:port" "]"
79 79
 Starts a lightweight Web server for development.
80 80
 .TP
81 81
 .BI "shell [" "\-\-plain" "]"
@@ -167,6 +167,9 @@ Disable the development server's auto\-reloader.
167 167
 .I \-\-nostatic
168 168
 Disable automatic serving of static files from STATIC_URL.
169 169
 .TP
  170
+.I \-\-nothreading
  171
+Disable the development server's threading.
  172
+.TP
170 173
 .I \-\-insecure
171 174
 Enables serving of static files even if DEBUG is False.
172 175
 .TP
7  docs/ref/django-admin.txt
@@ -688,6 +688,13 @@ Example usage::
688 688
 
689 689
     django-admin.py runserver --noreload
690 690
 
  691
+.. django-admin-option:: --nothreading
  692
+
  693
+.. versionadded:: 1.4
  694
+
  695
+Use the ``--nothreading`` option to disable the use of threading in the
  696
+development server.
  697
+
691 698
 .. django-admin-option:: --ipv6, -6
692 699
 
693 700
 .. versionadded:: 1.3

0 notes on commit ce165f7

Please sign in to comment.
Something went wrong with that request. Please try again.