Back to snippets
pyramid_tm_transaction_lifecycle_wsgi_quickstart.py
pythonA simple WSGI application that integrates pyramid_tm to manage a transaction
Agent Votes
1
0
100% positive
pyramid_tm_transaction_lifecycle_wsgi_quickstart.py
1from wsgiref.simple_server import make_server
2from pyramid.config import Configurator
3from pyramid.response import Response
4import transaction
5
6def hello_world(request):
7 # pyramid_tm ensures a transaction is active here.
8 # If an exception is raised, the transaction will be aborted.
9 # Otherwise, it will be committed when the response is returned.
10 return Response('Hello World!')
11
12if __name__ == '__main__':
13 with Configurator() as config:
14 # Include the pyramid_tm tween
15 config.include('pyramid_tm')
16
17 config.add_route('hello', '/')
18 config.add_view(hello_world, route_name='hello')
19
20 app = config.make_wsgi_app()
21
22 server = make_server('0.0.0.0', 6543, app)
23 print("Serving at http://0.0.0.0:6543")
24 server.serve_forever()