Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Now support multiple ipaddr/port pairs to invoke multiple servers at …

…the same

time.
  • Loading branch information...
commit 6f5d25269afb77aefa211320ee959b6628ec7533 1 parent 0679b37
David Koblas authored
Showing with 29 additions and 7 deletions.
  1. +29 −7 myproject/django_tornado/management/commands/runtornado.py
View
36 myproject/django_tornado/management/commands/runtornado.py
@@ -23,24 +23,46 @@ class Command(BaseCommand):
help="Tells Tornado to NOT keep alive http connections."),
)
help = "Starts a Tornado Web."
- args = '[optional port number, or ipaddr:port]'
+ args = '[optional port number or ipaddr:port] (one or more, will start multiple servers)'
# Validation is called explicitly each time the server is reloaded.
requires_model_validation = False
- def handle(self, addrport='', *args, **options):
- import django
- from django.core.handlers.wsgi import WSGIHandler
- from tornado import httpserver, wsgi, ioloop, web
-
+ def handle(self, *addrport, **options):
# reopen stdout/stderr file descriptor with write mode
# and 0 as the buffer size (unbuffered).
# XXX: why?
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 0)
- if args:
+ if len(addrport) == 0 :
raise CommandError('Usage is runserver %s' % self.args)
+
+ if len(addrport) == 1 :
+ self.run_one(addrport[0], **options)
+ else :
+ from multiprocessing import Process
+
+ plist = []
+ for ap in addrport :
+ p = Process(target=self.run_one, args=(ap,), kwargs=options)
+ p.start()
+ plist.append(p)
+
+ # for p in plist : plist.terminate()
+
+ while plist :
+ if plist[0].exitcode is None :
+ plist.pop(0)
+ else :
+ plist[0].join()
+
+
+ def run_one(self, addrport, **options) :
+ import django
+ from django.core.handlers.wsgi import WSGIHandler
+ from tornado import httpserver, wsgi, ioloop, web
+
if not addrport:
addr = ''
port = '8000'
Please sign in to comment.
Something went wrong with that request. Please try again.