Commit 99aa5fa4 authored by Laurence Rowe's avatar Laurence Rowe

add download link to chatter.py; add transaction abort to conflict handling

parent c70f34f6
...@@ -62,10 +62,10 @@ class ChatSession(Persistent): ...@@ -62,10 +62,10 @@ class ChatSession(Persistent):
self._messages[ now ] = message self._messages[ now ] = message
transaction.commit() transaction.commit()
except ConflictError: except ConflictError:
# Conflict occurred; this process should pause and # Conflict occurred; this process should abort,
# wait for a little bit, then try again. # wait for a little bit, then try again.
transaction.abort()
time.sleep(.2) time.sleep(.2)
pass
else: else:
# No ConflictError exception raised, so break # No ConflictError exception raised, so break
# out of the enclosing while loop. # out of the enclosing while loop.
......
...@@ -155,11 +155,10 @@ Sample Application: chatter.py ...@@ -155,11 +155,10 @@ Sample Application: chatter.py
For an example application, we'll build a little chat application. What's For an example application, we'll build a little chat application. What's
interesting is that none of the application's code deals with network interesting is that none of the application's code deals with network
programming at all; instead, an object will hold chat messages, and be magically programming at all; instead, an object will hold chat messages, and be
shared between all the clients through ZEO. I won't present the complete script magically shared between all the clients through ZEO. I won't present the
here; it's included in my ZODB distribution, and you can download it from complete script here; you can download it from :download:`chatter.py
`<http://www.amk.ca/zodb/demos/>`_. Only the interesting portions of the code <chatter.py>`. Only the interesting portions of the code will be covered here.
will be covered here.
The basic data structure is the :class:`ChatSession` object, which provides an The basic data structure is the :class:`ChatSession` object, which provides an
:meth:`add_message` method that adds a message, and a :meth:`new_messages` :meth:`add_message` method that adds a message, and a :meth:`new_messages`
...@@ -197,10 +196,10 @@ breaking out of the loop when the commit works without raising an exception. :: ...@@ -197,10 +196,10 @@ breaking out of the loop when the commit works without raising an exception. ::
self._messages[now] = message self._messages[now] = message
get_transaction().commit() get_transaction().commit()
except ConflictError: except ConflictError:
# Conflict occurred; this process should pause and # Conflict occurred; this process should abort,
# wait for a little bit, then try again. # wait for a little bit, then try again.
transaction.abort()
time.sleep(.2) time.sleep(.2)
pass
else: else:
# No ConflictError exception raised, so break # No ConflictError exception raised, so break
# out of the enclosing while loop. # out of the enclosing while loop.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment