mirror of https://github.com/django/django.git
Fixed #16099 -- Enabled threading for the runserver management command 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
This commit is contained in:
parent
838a16ec20
commit
ce165f7bbf
|
@ -17,10 +17,13 @@ naiveip_re = re.compile(r"""^(?:
|
||||||
):)?(?P<port>\d+)$""", re.X)
|
):)?(?P<port>\d+)$""", re.X)
|
||||||
DEFAULT_PORT = "8000"
|
DEFAULT_PORT = "8000"
|
||||||
|
|
||||||
|
|
||||||
class BaseRunserverCommand(BaseCommand):
|
class BaseRunserverCommand(BaseCommand):
|
||||||
option_list = BaseCommand.option_list + (
|
option_list = BaseCommand.option_list + (
|
||||||
make_option('--ipv6', '-6', action='store_true', dest='use_ipv6', default=False,
|
make_option('--ipv6', '-6', action='store_true', dest='use_ipv6', default=False,
|
||||||
help='Tells Django to use a IPv6 address.'),
|
help='Tells Django to use a IPv6 address.'),
|
||||||
|
make_option('--nothreading', action='store_false', dest='use_threading', default=True,
|
||||||
|
help='Use threading for web server.'),
|
||||||
make_option('--noreload', action='store_false', dest='use_reloader', default=True,
|
make_option('--noreload', action='store_false', dest='use_reloader', default=True,
|
||||||
help='Tells Django to NOT use the auto-reloader.'),
|
help='Tells Django to NOT use the auto-reloader.'),
|
||||||
)
|
)
|
||||||
|
@ -81,6 +84,7 @@ class BaseRunserverCommand(BaseCommand):
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
|
|
||||||
|
threading = options.get('use_threading', False)
|
||||||
shutdown_message = options.get('shutdown_message', '')
|
shutdown_message = options.get('shutdown_message', '')
|
||||||
quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'
|
quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'
|
||||||
|
|
||||||
|
@ -104,7 +108,8 @@ class BaseRunserverCommand(BaseCommand):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
handler = self.get_handler(*args, **options)
|
handler = self.get_handler(*args, **options)
|
||||||
run(self.addr, int(self.port), handler, ipv6=self.use_ipv6)
|
run(self.addr, int(self.port), handler,
|
||||||
|
ipv6=self.use_ipv6, threading=threading)
|
||||||
except WSGIServerException, e:
|
except WSGIServerException, e:
|
||||||
# Use helpful error messages instead of ugly tracebacks.
|
# Use helpful error messages instead of ugly tracebacks.
|
||||||
ERRORS = {
|
ERRORS = {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import socket
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
import urllib
|
import urllib
|
||||||
|
from SocketServer import ThreadingMixIn
|
||||||
from wsgiref import simple_server
|
from wsgiref import simple_server
|
||||||
from wsgiref.util import FileWrapper # for backwards compatibility
|
from wsgiref.util import FileWrapper # for backwards compatibility
|
||||||
|
|
||||||
|
@ -205,8 +206,12 @@ class AdminMediaHandler(handlers.StaticFilesHandler):
|
||||||
return path.startswith(self.base_url[2]) and not self.base_url[1]
|
return path.startswith(self.base_url[2]) and not self.base_url[1]
|
||||||
|
|
||||||
|
|
||||||
def run(addr, port, wsgi_handler, ipv6=False):
|
def run(addr, port, wsgi_handler, ipv6=False, threading=False):
|
||||||
server_address = (addr, port)
|
server_address = (addr, port)
|
||||||
httpd = WSGIServer(server_address, WSGIRequestHandler, ipv6=ipv6)
|
if threading:
|
||||||
|
httpd_cls = type('WSGIServer', (ThreadingMixIn, WSGIServer), {})
|
||||||
|
else:
|
||||||
|
httpd_cls = WSGIServer
|
||||||
|
httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
|
||||||
httpd.set_app(wsgi_handler)
|
httpd.set_app(wsgi_handler)
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|
|
@ -75,7 +75,7 @@ Runs this project as a FastCGI application. Requires flup. Use
|
||||||
.B runfcgi help
|
.B runfcgi help
|
||||||
for help on the KEY=val pairs.
|
for help on the KEY=val pairs.
|
||||||
.TP
|
.TP
|
||||||
.BI "runserver [" "\-\-noreload" "] [" "\-\-nostatic" "] [" "\-\-insecure" "] [" "\-\-ipv6" "] [" "\-\-adminmedia=ADMIN_MEDIA_PATH" "] [" "port|ipaddr:port" "]"
|
.BI "runserver [" "\-\-noreload" "] [" "\-\-nothreading" "] [" "\-\-nostatic" "] [" "\-\-insecure" "] [" "\-\-ipv6" "] [" "\-\-adminmedia=ADMIN_MEDIA_PATH" "] [" "port|ipaddr:port" "]"
|
||||||
Starts a lightweight Web server for development.
|
Starts a lightweight Web server for development.
|
||||||
.TP
|
.TP
|
||||||
.BI "shell [" "\-\-plain" "]"
|
.BI "shell [" "\-\-plain" "]"
|
||||||
|
@ -167,6 +167,9 @@ Disable the development server's auto\-reloader.
|
||||||
.I \-\-nostatic
|
.I \-\-nostatic
|
||||||
Disable automatic serving of static files from STATIC_URL.
|
Disable automatic serving of static files from STATIC_URL.
|
||||||
.TP
|
.TP
|
||||||
|
.I \-\-nothreading
|
||||||
|
Disable the development server's threading.
|
||||||
|
.TP
|
||||||
.I \-\-insecure
|
.I \-\-insecure
|
||||||
Enables serving of static files even if DEBUG is False.
|
Enables serving of static files even if DEBUG is False.
|
||||||
.TP
|
.TP
|
||||||
|
|
|
@ -688,6 +688,13 @@ Example usage::
|
||||||
|
|
||||||
django-admin.py runserver --noreload
|
django-admin.py runserver --noreload
|
||||||
|
|
||||||
|
.. django-admin-option:: --nothreading
|
||||||
|
|
||||||
|
.. versionadded:: 1.4
|
||||||
|
|
||||||
|
Use the ``--nothreading`` option to disable the use of threading in the
|
||||||
|
development server.
|
||||||
|
|
||||||
.. django-admin-option:: --ipv6, -6
|
.. django-admin-option:: --ipv6, -6
|
||||||
|
|
||||||
.. versionadded:: 1.3
|
.. versionadded:: 1.3
|
||||||
|
|
Loading…
Reference in New Issue