Commit b4e15c53 authored by Robin Schoonover's avatar Robin Schoonover
Browse files

Convert to using multiprocessing module for launching subprocess.

parent c66bc839
import logging
import multiprocessing
import os
import signal
import subprocess
import sys
import threading
import time
......@@ -30,14 +30,14 @@ class Server(object):
try:
proc = self.spawn_process()
self.process = proc
proc.wait()
proc.join()
except KeyboardInterrupt:
return self.quitting()
def quitting(self):
if self.process:
self.process.terminate()
self.process.wait()
self.process.join()
def spawn_process(self):
now = time.time()
......@@ -46,8 +46,13 @@ class Server(object):
time.sleep(1)
self.last_start = now
args = [sys.executable, "-m", __name__, self.app, str(self.host), str(self.port)]
return subprocess.Popen(args, stdin=subprocess.DEVNULL)
proc = multiprocessing.Process(target=ServerChild.launch, kwargs={
'app' : self.app,
'host' : self.host,
'port' : self.port
})
proc.start()
return proc
class ServerChild(object):
def __init__(self, app, host, port):
......@@ -57,6 +62,10 @@ class ServerChild(object):
self.module_times = {}
@classmethod
def launch(cls, *args, **kwargs):
return cls(*args, **kwargs).run_forever()
def run_forever(self):
self.reload_thread = threading.Thread(target=self.reload_main)
......@@ -121,6 +130,3 @@ class ServerChild(object):
time.sleep(1)
if __name__=='__main__':
# actual server starts here
ServerChild(sys.argv[1], sys.argv[2], int(sys.argv[3])).run_forever()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment