fix flask_nameko bug

This commit is contained in:
BryantHe 2023-06-01 04:10:42 +08:00
parent 4211be09be
commit 121cc2e30b
2 changed files with 8 additions and 5 deletions

View File

@ -19,15 +19,18 @@ class Connection(object):
def __getattr__(self, attr): def __getattr__(self, attr):
return getattr(self.connection, attr) return getattr(self.connection, attr)
def __del__(self):
self.connection.stop()
class ConnectionPool(object): class ConnectionPool(object):
def __init__( def __init__(
self, get_connection, initial_connections=2, max_connections=8, self, connection, initial_connections=2, max_connections=8,
recycle=None recycle=None
): ):
""" """
Create a new pool Create a new pool
:param func get_connection: The function that returns a connection :param func connection: The connection
:param int initial_connections: The initial number of connection :param int initial_connections: The initial number of connection
objects to create objects to create
:param int max_connections: The maximum amount of connections :param int max_connections: The maximum amount of connections
@ -37,7 +40,7 @@ class ConnectionPool(object):
:meth:`release_connection` :meth:`release_connection`
constructor constructor
""" """
self._get_connection = get_connection self._connection = connection
self._queue = Queue() self._queue = Queue()
self._current_connections = 0 self._current_connections = 0
self._max_connections = max_connections self._max_connections = max_connections
@ -49,7 +52,7 @@ class ConnectionPool(object):
self._queue.put(connection) self._queue.put(connection)
def _make_connection(self): def _make_connection(self):
ret = Connection(self._get_connection()) ret = Connection(self._connection)
self._current_connections += 1 self._current_connections += 1
return ret return ret

View File

@ -71,7 +71,7 @@ class FlaskPooledClusterRpcProxy(PooledClusterRpcProxy):
for key, val in app.config.items(): for key, val in app.config.items():
match = re.match(r"NAMEKO\_(?P<name>.*)", key) match = re.match(r"NAMEKO\_(?P<name>.*)", key)
if match: if match:
config[match.group('name')] = val config['uri'] = val
self.configure(config) self.configure(config)
self._connect_on_method_call = config.get( self._connect_on_method_call = config.get(