Merge pull request #12 from j1z0/master
Pull request to allow for setting number of threads in default cherrypy server
This commit is contained in:
commit
22fca66b1b
5 changed files with 29 additions and 9 deletions
|
@ -78,13 +78,13 @@ class DjangoContext(Vows.Context):
|
|||
|
||||
class DjangoHTTPContext(DjangoContext):
|
||||
|
||||
def start_server(self, host=None, port=None, settings={}):
|
||||
def start_server(self, host=None, port=None, settings={}, threads=1):
|
||||
if not port: port = DEFAULT_PORT
|
||||
if not host: host = DEFAULT_HOST
|
||||
|
||||
self.address = (host, port)
|
||||
self.server = DjangoServer(host, port)
|
||||
self.server.start(settings)
|
||||
self.server.start(settings,threads)
|
||||
|
||||
def __init__(self, parent):
|
||||
super(DjangoHTTPContext, self).__init__(parent)
|
||||
|
|
|
@ -16,12 +16,12 @@ from cherrypy import wsgiserver
|
|||
from django.core.handlers.wsgi import WSGIHandler
|
||||
|
||||
|
||||
def run_app(host, port):
|
||||
def run_app(host, port, thread_count):
|
||||
server = wsgiserver.CherryPyWSGIServer(
|
||||
(host, port),
|
||||
(host, port),
|
||||
WSGIHandler(),
|
||||
server_name='tornado-pyvows',
|
||||
numthreads = 1
|
||||
numthreads = thread_count
|
||||
)
|
||||
|
||||
my_thread = current_thread()
|
||||
|
@ -35,11 +35,11 @@ def run_app(host, port):
|
|||
class DjangoServer(object):
|
||||
|
||||
def __init__(self, host, port):
|
||||
self.host = host
|
||||
self.host = host
|
||||
self.port = port
|
||||
|
||||
def start(self, settings):
|
||||
self.thr = Thread(target=run_app, args=(self.host, self.port))
|
||||
def start(self, settings, thread_count=1):
|
||||
self.thr = Thread(target= run_app, args=(self.host, self.port, thread_count))
|
||||
self.thr.daemon = True
|
||||
self.thr.settings = {}
|
||||
for k, v in settings.iteritems():
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
django==1.3.1
|
||||
pyvows==0.8.3
|
||||
pyvows
|
||||
coverage==3.5.1
|
||||
httplib2
|
||||
lxml
|
||||
cssselect
|
||||
cherrypy
|
||||
|
|
|
@ -57,6 +57,9 @@ class ContextTest(Vows.Context):
|
|||
|
||||
def setup(self):
|
||||
self.start_server(port=8085)
|
||||
|
||||
def should_default_to_one_thread(self,topic):
|
||||
expect(self.server.thr.server._get_numthreads()).to_equal(1)
|
||||
|
||||
class WithinDjangoHTTPContextTheGetUrlMethod(DjangoHTTPContext):
|
||||
|
||||
|
@ -100,3 +103,15 @@ class ContextTest(Vows.Context):
|
|||
def the_get_url_method_should_return_a_well_formed_url(self, topic):
|
||||
expect(topic).to_equal('http://127.0.0.1:8085/')
|
||||
|
||||
class WithinAMultiThreadedServer(DjangoHTTPContext):
|
||||
|
||||
def setup(self):
|
||||
self.start_server(threads=5)
|
||||
|
||||
def topic(self):
|
||||
return self.server
|
||||
|
||||
def should_allow_user_to_specify_number_of_threads(self,topic):
|
||||
expect(topic.thr.server._get_numthreads()).to_equal(5)
|
||||
|
||||
|
||||
|
|
|
@ -80,3 +80,4 @@ class HttpContextVows(DjangoHTTPContext):
|
|||
def should_be_404(self, (topic, content)):
|
||||
expect(topic.status).to_equal(404)
|
||||
|
||||
|
||||
|
|
Reference in a new issue