How do I commit partial results from an external script?
I need to remove an attribute from most any object in my zodb. I suspect that I will need to do partial commits to not slow down the process to much. Has anybody got an example? regards Max M "Skeptic Effect" or the "Randi Effect" When a skeptic is near, supernatural effects seem to disappear.
On Friday 30 Aug 2002 11:16 am, Max M wrote:
I need to remove an attribute from most any object in my zodb. I suspect that I will need to do partial commits to not slow down the process to much.
Has anybody got an example?
Have a look at how the catalog_object function in ZCatalog.py uses subtransactions.
Toby Dickenson wrote:
On Friday 30 Aug 2002 11:16 am, Max M wrote:
I need to remove an attribute from most any object in my zodb. I suspect that I will need to do partial commits to not slow down the process to much.
Has anybody got an example?
Have a look at how the catalog_object function in ZCatalog.py uses subtransactions.
It was actually quite simple, except that Zope plays a trick. The key to the problem is that "get_transaction()" by magic is a "built in" function in Zope. Also in external methods. It kind of fazed me that I could not see where get_transaction() was imported from. Well it wasn't :-s so I just did something like: i = 1 transaction = get_transaction() for obj in aLotOfObjects: update(obj) if not i % 200: transaction.commit(1) # partial transaction i += 1 regards Max M "Skeptic Effect" or the "Randi Effect" When a skeptic is near, supernatural effects seem to disappear.
you could just use a simple counter variable that gets incremented for every object you work on. then in your loop you could check the counter and commit every n times (meaning where counter != 0 and counter % n == 0). ***** counter = 0 <code that crals the ZODB> <code that manipulates the object> counter += 1 if counter % 50 == 0: get_transaction().commit() jens On Friday, Aug 30, 2002, at 06:16 US/Eastern, Max M wrote:
I need to remove an attribute from most any object in my zodb. I suspect that I will need to do partial commits to not slow down the process to much.
Has anybody got an example?
regards Max M
participants (3)
-
Jens Vagelpohl -
Max M -
Toby Dickenson