[Twisted-Python] Re: My project is using Twisted

Martin Geisler mg at daimi.au.dk
Tue Mar 18 10:11:55 EDT 2008


Itamar Shtull-Trauring <itamar at itamarst.org> writes:

> On Tue, 2008-03-18 at 10:57 +0100, Martin Geisler wrote:
>> Hi,
>> 
>> I would like to ask if a link could be added to my VIFF project on
>> the Projects Using Twisted page:
>
> Done.

Thank you!

And thank you all for Twisted, I have been very happy with it,
especially the asynchronous style of programming offered by Deferreds
which fits the needs of my project perfectly.

We basically need to evaluate arithmetic circuits as fast as possible,
and so we want to execute a gate as soon as the operands are ready. It
turned out that Deferreds lets us define the execution tree
implicitly, something like this:

  def add(a, b):
    result = gatherResults([a, b])
    result.addCallback(lambda (a, b): a + b)
    return result

  def mul(a, b):
    result = gatherResults([a, b])
    result.addCallback(lambda (a, b): a * b)
    return result

  x = Deferred()
  y = Deferred()
  z = Deferred()
  w = mul(add(x, y), mul(x, add(x, z)))

Here w is calculated as fast as possible, namely when x, y, and z are
available.

I would not even know how to program something like this in a sane way
in, say, Java, but with Twisted (and thanks to lambda expressions) it
is very easy to get the fine-grained execution we want.

-- 
Martin Geisler

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





More information about the Twisted-Python mailing list