Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-185-NullPool-logging-messages-appear-during-execution ec8effbdb -> 41e967fe7
shuffled things around Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/41e967fe Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/41e967fe Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/41e967fe Branch: refs/heads/ARIA-185-NullPool-logging-messages-appear-during-execution Commit: 41e967fe7a9ad563c0715e6adb347a9d2bd434cc Parents: ec8effb Author: max-orlov <[email protected]> Authored: Wed May 24 12:07:32 2017 +0300 Committer: max-orlov <[email protected]> Committed: Wed May 24 12:07:32 2017 +0300 ---------------------------------------------------------------------- .../execution_plugin/ctx_proxy/server.py | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/41e967fe/aria/orchestrator/execution_plugin/ctx_proxy/server.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/execution_plugin/ctx_proxy/server.py b/aria/orchestrator/execution_plugin/ctx_proxy/server.py index d59e7bf..bc89fde 100644 --- a/aria/orchestrator/execution_plugin/ctx_proxy/server.py +++ b/aria/orchestrator/execution_plugin/ctx_proxy/server.py @@ -37,18 +37,14 @@ class CtxProxy(object): self.port = _get_unused_port() self.socket_url = 'http://localhost:{0}'.format(self.port) self.server = None - self.bottle_server = None self._started = Queue.Queue(1) self.thread = self._start_server() self._started.get(timeout=5) def _start_server(self): - proxy = self class BottleServerAdapter(bottle.ServerAdapter): - def __init__(self, _session, *args, **kwargs): - super(BottleServerAdapter, self).__init__(*args, **kwargs) - self._session = _session + proxy = self def run(self, app): @@ -56,15 +52,20 @@ class CtxProxy(object): allow_reuse_address = True bottle_server = self + def close_session(self): + self.bottle_server.proxy.ctx.model.log._session.remove() + def handle_error(self, request, client_address): pass def serve_forever(self, poll_interval=0.5): try: wsgiref.simple_server.WSGIServer.serve_forever(self, poll_interval) - # Once shutdown is called, we need to close the session finally: - self.bottle_server._session.remove() + # Once shutdown is called, we need to close the session. + # If the session is not closed properly, it might raise warnings, + # or even lock the database. + self.close_session() class Handler(wsgiref.simple_server.WSGIRequestHandler): def address_string(self): @@ -80,8 +81,8 @@ class CtxProxy(object): app=app, server_class=Server, handler_class=Handler) - proxy.server = server - proxy._started.put(True) + self.proxy.server = server + self.proxy._started.put(True) server.serve_forever(poll_interval=0.1) def serve(): @@ -95,8 +96,7 @@ class CtxProxy(object): host='localhost', port=self.port, quiet=True, - server=BottleServerAdapter, - _session=proxy.ctx.model.log._session) + server=BottleServerAdapter) thread = threading.Thread(target=serve) thread.daemon = True thread.start()
