[ZODB-Dev] newbie ZEO first try. ConflictError.
tsmiller
tsmiller at gnixterhouse.com
Thu Nov 26 16:43:51 EST 2009
James,
You were right. I moved the assignment into the inner loop where is is
reassigned each time after the abort. However, if I do not put the abort()
in, then the ZODB comes back with a ConflictError and actually dies with a
TransactionFailedError. The commit() is the purpose of the entire thing.
To save my changes to the database. And if the commit() does not work the
first time, then the loop waits a little while and trys the commit() again.
I have two programs now so that I could differentiate which one was actually
committing, and I still get a ConflictError every time a transaction is
tried.
while True:
while True:
## one program prints out program 1 and the other
program 2 to show origin of commit
root[ "one" ] = "program 2 - " + time.asctime()
try:
print "Try to commit transaction"
transaction.commit()
print "root is", root
except POSException.ConflictError:
print "we have a conflict"
transaction.abort()
time.sleep(.2)
else:
break
time.sleep(10)
output:
we have a conflict
Try to commit transaction
root is {'one': 'program 2 - Thu Nov 26 14:29:02 2009'}
Try to commit transaction
we have a conflict
Try to commit transaction
root is {'one': 'program 2 - Thu Nov 26 14:29:12 2009'}
Try to commit transaction
we have a conflict
Try to commit transaction
root is {'one': 'program 2 - Thu Nov 26 14:29:22 2009'}
Try to commit transaction
we have a conflict
James Bergstra-2 wrote:
>
> On Thu, Nov 26, 2009 at 1:51 PM, tsmiller <tsmiller at gnixterhouse.com>
> wrote:
>>
>> Laurence,
>> Thank you for your very quick reply. I did as you suggested and now the
>> ConflictError is now handled. And that is a most excellent thing because
>> now ConflictError is raised every time. So it still seems to be
>> confused.
>> I am trying to figure out if I will be able to use ZEO in my application.
>>
>> Now my program reads:
>>
>> while True:
>> root[ "one" ] = time.asctime()
>> while True:
>> try:
>> print "Try to commit transaction"
>> transaction.commit()
>> print "root is", root
>> except POSException.ConflictError:
>> print "we have a conflict"
>> transaction.abort()
>> time.sleep(.2)
>> else:
>> break
>>
>> time.sleep(10)
>>
>
> I have a related question about this code... in the inner loop tom is
> calling abort() ; sleep(); commit(). Does that make sense?
>
> I thought that abort() would revert the root to the database's version
> of things, and discard any change that the client had tried to make.
> So what does it mean to call commit() again immediately and why that
> commit cause a conflict when the client hasn't actually changed
> anything since abort() ?
>
> James
> --
> http://www-etud.iro.umontreal.ca/~bergstrj
> _______________________________________________
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
>
> ZODB-Dev mailing list - ZODB-Dev at zope.org
> https://mail.zope.org/mailman/listinfo/zodb-dev
>
>
--
View this message in context: http://old.nabble.com/newbie-ZEO-first-try.--ConflictError.-tp26532984p26535272.html
Sent from the Zope - ZODB-Dev mailing list archive at Nabble.com.
More information about the ZODB-Dev
mailing list