summaryrefslogtreecommitdiffstats
path: root/openstack/common/wsgi.py
diff options
context:
space:
mode:
authorDavanum Srinivas <dims@linux.vnet.ibm.com>2012-11-27 22:11:40 -0500
committerDavanum Srinivas <dims@linux.vnet.ibm.com>2012-11-29 09:57:31 -0500
commit83186053c16d7536f90b4e6b3f95bd16d26bfb8c (patch)
tree474c2219024ef89630bdf6ed05f09e040a520338 /openstack/common/wsgi.py
parent582cb960066a02ae247097c8a96484655429fbe1 (diff)
downloadoslo-83186053c16d7536f90b4e6b3f95bd16d26bfb8c.tar.gz
oslo-83186053c16d7536f90b4e6b3f95bd16d26bfb8c.tar.xz
oslo-83186053c16d7536f90b4e6b3f95bd16d26bfb8c.zip
Use Service thread group for WSGI request handling
- Reuse the pool from thread group in service.Service instead of creating a new green pool - Add ability to control the size of the pool in service.Service - Add a couple of tests for wsgi.Service() to test the size of pool a start/stop as well - Get rid of the wait method by using tg.add_thread - Get rid of pool in wsgi.Service - Added explicit property for host and port Fixes LP #1050379 Change-Id: I40507dc7887fb036ec594bb167cdaa42c278607e
Diffstat (limited to 'openstack/common/wsgi.py')
-rw-r--r--openstack/common/wsgi.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/openstack/common/wsgi.py b/openstack/common/wsgi.py
index aaeb07b..dc49931 100644
--- a/openstack/common/wsgi.py
+++ b/openstack/common/wsgi.py
@@ -56,8 +56,7 @@ class Service(service.Service):
"""
def __init__(self, threads=1000):
- super(Service, self).__init__()
- self.pool = eventlet.GreenPool(threads)
+ super(Service, self).__init__(threads)
def start(self, application, port, host='0.0.0.0', backlog=128):
"""Start serving this service using the provided server instance.
@@ -67,7 +66,16 @@ class Service(service.Service):
"""
super(Service, self).start()
socket = eventlet.listen((host, port), backlog=backlog)
- self.pool.spawn_n(self._run, application, socket)
+ (self._host, self._port) = socket.getsockname()
+ self.tg.add_thread(self._run, application, socket)
+
+ @property
+ def host(self):
+ return self._host
+
+ @property
+ def port(self):
+ return self._port
def stop(self):
"""Stop serving this API.
@@ -77,18 +85,10 @@ class Service(service.Service):
"""
super(Service, self).stop()
- def wait(self):
- """Wait until all servers have completed running."""
- super(Service, self).wait()
- try:
- self.pool.waitall()
- except KeyboardInterrupt:
- pass
-
def _run(self, application, socket):
"""Start a WSGI server in a new green thread."""
logger = logging.getLogger('eventlet.wsgi.server')
- eventlet.wsgi.server(socket, application, custom_pool=self.pool,
+ eventlet.wsgi.server(socket, application, custom_pool=self.tg.pool,
log=logging.WritableLogger(logger))