[server] extract creating a new cnxset in a _new_cnxset() helper draft
authorPhilippe Pepiot <ph@itsalwaysdns.eu>
Mon, 30 Mar 2020 15:23:56 +0200
changeset 12960 2c3a8a4f5a02
parent 12959 39ee325e6758
child 12961 01810941a4be
[server] extract creating a new cnxset in a _new_cnxset() helper So we can move logic specific to _CnxSetPool here.
cubicweb/server/repository.py
--- a/cubicweb/server/repository.py	Mon Mar 30 15:19:23 2020 +0200
+++ b/cubicweb/server/repository.py	Mon Mar 30 15:23:56 2020 +0200
@@ -152,6 +152,9 @@
         return None
 
     def get(self):
+        return self._new_cnxset()
+
+    def _new_cnxset(self):
         return self._source.wrapped_connection()
 
     def release(self, cnxset):
@@ -173,9 +176,12 @@
         self._queue = queue.Queue()
 
         for i in range(size):
-            cnxset = source.wrapped_connection()
-            self._cnxsets.append(cnxset)
-            self._queue.put_nowait(cnxset)
+            self._queue.put_nowait(self._new_cnxset())
+
+    def _new_cnxset(self):
+        cnxset = super()._new_cnxset()
+        self._cnxsets.append(cnxset)
+        return cnxset
 
     def qsize(self):
         return self._queue.qsize()