From 788748e2afedb3d1e180a3033e20ed2d995056a3 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Wed, 13 Jan 2010 15:14:03 +0000 Subject: - In ``bfg_routesalchemy``, ``bfg_alchemy`` and ``bfgwiki2`` tutorial, clean up the SQLAlchemy connection by registering a ``repoze.tm.after_end`` callback instead of relying on a ``__del__`` method of a ``Cleanup`` class added to the WSFI environment. The ``__del__`` strategy was fragile and caused problems in the wild. Thanks to Daniel Holth for testing. --- docs/tutorials/bfgwiki2/basiclayout.rst | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'docs/tutorials/bfgwiki2/basiclayout.rst') diff --git a/docs/tutorials/bfgwiki2/basiclayout.rst b/docs/tutorials/bfgwiki2/basiclayout.rst index 5392660da..d30d919c1 100644 --- a/docs/tutorials/bfgwiki2/basiclayout.rst +++ b/docs/tutorials/bfgwiki2/basiclayout.rst @@ -119,26 +119,21 @@ function within the file named ``run.py``: :linenos: :language: py -#. *Lines 1-4*. Imports to support later code. +#. *Lines 1-8*. Imports to support later code. -#. *Lines 6-10*. We define a ``Cleanup`` class which has a - ``__del__`` method (the method called at Python object - destruction), which calls a function. +#. *Lines 10-14*. An event :term:`subscriber` which performs cleanup + at transaction boundaries. As a result of registering this event + subscriber, after the current transaction is committed or aborted, + our database connection will be removed. -#. *Lines 12-14*. An event :term:`subscriber` which adds a - ``Cleanup`` instance to the WSGI environment as - ``tutorial.sasession``. As a result of registering this event - subscriber, when the WSGI environment is cleaned up, our database - connection will be removed. - -#. *Lines 21-23*. Get the database configuration string from the +#. *Lines 22-25*. Get the database configuration string from the ``tutorial.ini`` file's ``[app:sql]`` section. This will be a URI (something like ``sqlite://``). -#. Line *24*. We initialize our SQL database using SQLAlchemy, passing +#. Line *26*. We initialize our SQL database using SQLAlchemy, passing it the db string. -#. *Line 25*. We construct a :term:`Configurator`. The first +#. *Line 27*. We construct a :term:`Configurator`. The first argument provided to the configurator is the :term:`root factory`, which is used by the :mod:`repoze.bfg` :term:`traversal` mechanism. Since this is a URL dispatch application, the root factory is @@ -146,7 +141,7 @@ function within the file named ``run.py``: argument. It contains a dictionary of settings parsed by PasteDeploy. -#. *Lines 26-29*. We then load a ZCML file to do application +#. *Lines 28-31*. We then load a ZCML file to do application configuration, and use the :meth:`repoze.bfg.configuration.Configurator.make_wsgi_app` method to return a :term:`WSGI` application. -- cgit v1.2.3