From 81de5dcd6090dc02bcb8a5617d1200fed91b7517 Mon Sep 17 00:00:00 2001 From: BryantHe Date: Thu, 1 Jun 2023 04:33:41 +0800 Subject: [PATCH] fix flask_nameko bug 3 --- chassis/flask_nameko/connection_pool.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/chassis/flask_nameko/connection_pool.py b/chassis/flask_nameko/connection_pool.py index a47100e..203f1a3 100644 --- a/chassis/flask_nameko/connection_pool.py +++ b/chassis/flask_nameko/connection_pool.py @@ -19,18 +19,15 @@ class Connection(object): def __getattr__(self, attr): return getattr(self.connection, attr) - def __del__(self): - self.connection.stop() - class ConnectionPool(object): def __init__( - self, connection, initial_connections=2, max_connections=8, + self, get_connection, initial_connections=2, max_connections=8, recycle=None ): """ Create a new pool - :param func connection: The connection + :param func get_connection: The function that returns a connection :param int initial_connections: The initial number of connection objects to create :param int max_connections: The maximum amount of connections @@ -40,7 +37,7 @@ class ConnectionPool(object): :meth:`release_connection` constructor """ - self._connection = connection + self._get_connection = get_connection self._queue = Queue() self._current_connections = 0 self._max_connections = max_connections @@ -52,7 +49,7 @@ class ConnectionPool(object): self._queue.put(connection) def _make_connection(self): - ret = Connection(self._connection) + ret = Connection(self._get_connection()) self._current_connections += 1 return ret