Discussion:
[PATCH 1 of 1] Clone errors
Thomas P Jakobsen
2009-06-11 12:15:47 UTC
Permalink
# HG changeset patch
# User Thomas P Jakobsen <***@cs.au.dk>
# Date 1244721950 -7200
# Node ID e1270881794e39f81445820c4133fad317af6e0f
# Parent 8ec45943c12ab91430d03a8895aabc6f64fe7a37
Clone errors.

diff -r 8ec45943c12a -r e1270881794e viff/util.py
--- a/viff/util.py Wed May 27 22:29:31 2009 +0200
+++ b/viff/util.py Thu Jun 11 14:05:50 2009 +0200
@@ -185,12 +185,16 @@
print fmt % tuple(args)


-def clone_deferred(original):
+def clone_deferred(original, splitErr=True):
"""Clone a Deferred.

The returned clone will fire with the same result as the original
:class:`Deferred`, but will otherwise be independent.

+ If *splitErr* is true errors will propagate to both the original
+ and the cloned deferred. If *splitErr* is false errors only
+ propagate into the cloned deferred.
+
It is an error to call :meth:`callback` on the clone as it will
result in an :exc:`AlreadyCalledError` when the original
:class:`Deferred` is triggered.
@@ -212,8 +216,12 @@
def split_result(result):
clone.callback(result)
return result
+ def split_err(error):
+ if splitErr:
+ clone.errback(error)
+ return result
clone = Deferred()
- original.addCallback(split_result)
+ original.addCallbacks(split_result, split_err)
return clone
Martin Geisler
2009-06-11 13:49:10 UTC
Permalink
Post by Thomas P Jakobsen
# HG changeset patch
# Date 1244721950 -7200
# Node ID e1270881794e39f81445820c4133fad317af6e0f
# Parent 8ec45943c12ab91430d03a8895aabc6f64fe7a37
Clone errors.
Please don't make a big and interesting [0 of 1] mail with all the good
stuff and then leave out the explaination in the commit message.
Post by Thomas P Jakobsen
diff -r 8ec45943c12a -r e1270881794e viff/util.py
--- a/viff/util.py Wed May 27 22:29:31 2009 +0200
+++ b/viff/util.py Thu Jun 11 14:05:50 2009 +0200
@@ -185,12 +185,16 @@
print fmt % tuple(args)
It should be called split_err to follow the normal code style.
Post by Thomas P Jakobsen
"""Clone a Deferred.
The returned clone will fire with the same result as the original
:class:`Deferred`, but will otherwise be independent.
+ If *splitErr* is true errors will propagate to both the original
+ and the cloned deferred. If *splitErr* is false errors only
+ propagate into the cloned deferred.
+
It is an error to call :meth:`callback` on the clone as it will
result in an :exc:`AlreadyCalledError` when the original
:class:`Deferred` is triggered.
@@ -212,8 +216,12 @@
clone.callback(result)
return result
+ clone.errback(error)
+ return result
what is 'result' here?
Post by Thomas P Jakobsen
clone = Deferred()
- original.addCallback(split_result)
+ original.addCallbacks(split_result, split_err)
return clone
Should this also be done for the clone method in Share? Or maybe one of
the two could be deleted?
--
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.
Loading...