From 0f2232648cd191a1e4ce7290bc83a7f7f5472768 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Fri, 25 Oct 2024 15:08:08 +0200 Subject: [PATCH] psu improvments for db and conn usage; fix table.py --- loops/server/psu.py | 16 ++++++++++++---- loops/table.py | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/loops/server/psu.py b/loops/server/psu.py index da3ab88..19a94fa 100644 --- a/loops/server/psu.py +++ b/loops/server/psu.py @@ -43,22 +43,30 @@ except ImportError: sc = Jeep() # shortcuts +db = None conn = None def closeConnection(): + global conn if conn is not None: print('closing ZODB connection...') conn.close() + conn = None + +atexit.register(closeConnection) def setup(zope_conf=None, loopsRootPath=None, config=config): if zope_conf is None: zope_conf = getattr(config, 'zope_conf', 'zope.conf') if loopsRootPath is None: loopsRootPath = getattr(config, 'loops_path', None) - global conn, root, sm, smdefault, intids, pau, loopsRoot, sc - print(f'opening ZODB connection... - conf: {zope_conf}, path: {loopsRootPath}') - conn = wsgi.config(zope_conf).open() - atexit.register(closeConnection) + global db, conn, root, sm, smdefault, intids, pau, loopsRoot, sc + if db is None: + print(f'setting up ZODB... - conf: {zope_conf}, path: {loopsRootPath}') + db = wsgi.config(zope_conf) + if conn is None: + print(f'opening ZODB connection...') + conn = db.open() root = conn.root()['Application'] setSite(root) sm = component.getSiteManager(root) diff --git a/loops/table.py b/loops/table.py index c888c6a..06c5d74 100644 --- a/loops/table.py +++ b/loops/table.py @@ -131,7 +131,7 @@ def getRowValue(k, v): return v[0] def getRowValueWithKey(k, v): - return ' '.join((k, v[0])) + return ' '.join((str(k), v[0])) @implementer(IIterableSource)