[pyramid] Call repository's shutdown method atexit
authorDenis Laxalde <denis.laxalde@logilab.fr>
Fri, 10 Mar 2017 12:02:41 +0100
changeset 12052 1a1d2f5faddb
parent 12051 bff3be6eebed
child 12053 c3c9f2e1424c
[pyramid] Call repository's shutdown method atexit This way when run through a WSGI server (pserve, gunicorn, etc.) we make sure that the repository is properly shut down. In particular, this would wait for threads to terminate (otherwise, they'll be killed).
cubicweb/pyramid/__init__.py
--- a/cubicweb/pyramid/__init__.py	Fri Mar 03 11:13:03 2017 +0100
+++ b/cubicweb/pyramid/__init__.py	Fri Mar 10 12:02:41 2017 +0100
@@ -20,8 +20,10 @@
 
 """Pyramid interface to CubicWeb"""
 
+import atexit
 import os
 from warnings import warn
+
 import wsgicors
 
 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg
@@ -224,6 +226,8 @@
         repo = config.registry['cubicweb.repository'] = cwconfig.repository()
     config.registry['cubicweb.registry'] = repo.vreg
 
+    atexit.register(repo.shutdown)
+
     if asbool(config.registry.settings.get('cubicweb.defaults', True)):
         config.include('cubicweb.pyramid.defaults')