mitsuhiko/werkzeug — pull request #444 by Cosmius (2013-10-08 06:50:14+00:00)
Title: Add default callback and release callbacks to LocalStack

A possible use, with SQLAlchemy

```python
_dbsession_stack = LocalStack(DBSession, (DBSession.remove, ))
dbsession = _dbsession_stack()
local_manager = LocalManager([_dbsession_stack])

@local_manager.middleware
def application(environ, start_response):
# Do something with dbsession here
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['Hello World']
```

compared to pushing everytime, if the callback consumes a lot of resource (CPU, memory, etc.) this approach can save the resource when the stack is not used anywhere.