[pyramid] Avoid shutting down the repository at exit if it's already shutting down 3.25
authorDenis Laxalde <denis.laxalde@logilab.fr>
Fri, 07 Apr 2017 15:23:38 +0200
branch3.25
changeset 12137 4db0f2251960
parent 12136 6069ee7d4824
child 12138 10a18c6c5e10
[pyramid] Avoid shutting down the repository at exit if it's already shutting down For install `cubicweb-ctl pyramid` command will explicitly call `repo.shutdown()` so the atexit hook is redundant. Prevent the latter to be executed when the repository is already shutting down (otherwise one gets an assertion error).
cubicweb/pyramid/__init__.py
--- a/cubicweb/pyramid/__init__.py	Wed Apr 05 14:42:30 2017 +0200
+++ b/cubicweb/pyramid/__init__.py	Fri Apr 07 15:23:38 2017 +0200
@@ -226,7 +226,11 @@
     config.registry['cubicweb.registry'] = repo.vreg
 
     if cwconfig.mode != 'test':
-        atexit.register(repo.shutdown)
+        @atexit.register
+        def shutdown_repo():
+            if repo.shutting_down:
+                return
+            repo.shutdown
 
     if asbool(config.registry.settings.get('cubicweb.defaults', True)):
         config.include('cubicweb.pyramid.defaults')