#3357: Make Django's server optionally multithreaded
-------------------------------------+-------------------------------------
               Reporter:             |        Owner:  adrian
  treborhudson@…                     |       Status:  closed
                   Type:             |    Component:  django-admin.py
  Uncategorized                      |  runserver
              Milestone:             |     Severity:  Normal
                Version:  SVN        |     Keywords:  post10
             Resolution:  wontfix    |    Has patch:  1
           Triage Stage:  Design     |  Needs tests:  0
  decision needed                    |
    Needs documentation:  0          |
Patch needs improvement:  0          |
-------------------------------------+-------------------------------------
Changes (by egenix_viktor):

 * type:   => Uncategorized
 * severity:   => Normal


Comment:

 Workaround for multi-threaded development, if you really need that. It is
 useful if you have to debug long polling (Comet) connections or stream
 content to the client, which would need more than one HTTP connection open
 at the same time. Create a new main script in your Django project
 directory with the following contents and use that to run your project
 inside the debugger (like Wing IDE):

 {{{
 """ Start Django in multithreaded mode

 It is NOT for deployment. It allows for debugging Django
 while serving multiple requests at once in multi-threaded mode.

 """

 import os, sys

 HOST = '127.0.0.1'
 PORT = 8000

 DJANGO_PROJECT_DIR = os.path.dirname(__file__)
 PARENT_DIR, DJANGO_PROJECT_NAME = DJANGO_PROJECT_DIR.rsplit(os.sep, 1)

 sys.path.append(DJANGO_PROJECT_DIR)
 os.environ['DJANGO_SETTINGS_MODULE'] = '%s.settings' % DJANGO_PROJECT_NAME

 import django
 import django.core.handlers.wsgi

 application = django.core.handlers.wsgi.WSGIHandler()

 if __name__ == '__main__':
     import wsgiref, SocketServer
     from wsgiref import simple_server
     class ThreadedWSGIServer(SocketServer.ThreadingMixIn,
 simple_server.WSGIServer):
         pass
     httpd = simple_server.make_server(
         HOST, PORT, application, server_class=ThreadedWSGIServer)
     print 'Serving on port %s:%d' % (HOST, PORT)
     httpd.serve_forever()
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/3357#comment:26>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to