From 4926ff837bb3f572a1ae8acfdf4094f431bfd170 Mon Sep 17 00:00:00 2001 From: baloan Date: Tue, 16 Dec 2014 22:31:24 +0100 Subject: [PATCH] transaction context manager added --HG-- branch : sandbox --- src/zodb/tutorial.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/zodb/tutorial.py b/src/zodb/tutorial.py index 2f36646..946cd37 100644 --- a/src/zodb/tutorial.py +++ b/src/zodb/tutorial.py @@ -14,6 +14,7 @@ from __future__ import unicode_literals from ZODB.FileStorage import FileStorage from ZODB.DB import DB +from ZEO.ClientStorage import ClientStorage from persistent import Persistent import transaction @@ -33,7 +34,8 @@ class Account(Persistent): # Configuration -storage = FileStorage(r"e:\workspaces\zodb3\tutorial.zodb") +# storage = FileStorage(r"e:\workspaces\zodb3\tutorial.zodb") +storage = ClientStorage(8090) db = DB(storage) ctx = db.open() root = ctx.root() @@ -62,6 +64,7 @@ print(root.keys()) # ['account-1', 'account-2'] print(root['account-2'].balance) -a = root['account-1'] -b = root['account-2'] +with transaction.manager: + a = root['account-1'] + b = root['account-2'] print("id(a): {}, id(b): {}".format(id(a), id(b)))