viff

changeset 1176:e86a007bddbd

Merged with Marcel.
author Martin Geisler <mg@cs.au.dk>
date Thu, 07 May 2009 11:09:47 +0200
parents 38e4007378df d6ff18bd643c
children a1304b0072d4 e1e0c107c40b
files viff/runtime.py
diffstat 8 files changed, 17 insertions(+), 21 deletions(-) [+]
line diff
     1.1 --- a/apps/aes.py	Wed Apr 29 09:39:21 2009 +0200
     1.2 +++ b/apps/aes.py	Thu May 07 11:09:47 2009 +0200
     1.3 @@ -81,7 +81,7 @@
     1.4          rt.shutdown()
     1.5  
     1.6      g = gather_shares(opened_ciphertext)
     1.7 -    g.addCallback(fin)
     1.8 +    rt.schedule_callback(g, fin)
     1.9  
    1.10  def share_key(rt):
    1.11      key =  []
     2.1 --- a/apps/millionaires.py	Wed Apr 29 09:39:21 2009 +0200
     2.2 +++ b/apps/millionaires.py	Thu May 07 11:09:47 2009 +0200
     2.3 @@ -97,10 +97,10 @@
     2.4          # the argument (which is None since self.results_ready does
     2.5          # not return anything), so we throw it away using a lambda
     2.6          # expressions which ignores its first argument.
     2.7 -        results.addCallback(lambda _: runtime.synchronize())
     2.8 +        runtime.schedule_callback(results, lambda _: runtime.synchronize())
     2.9          # The next callback shuts the runtime down, killing the
    2.10          # connections between the players.
    2.11 -        results.addCallback(lambda _: runtime.shutdown())
    2.12 +        runtime.schedule_callback(results, lambda _: runtime.shutdown())
    2.13  
    2.14      def results_ready(self, results):
    2.15          # Since this method is called as a callback above, the results
     3.1 --- a/viff/active.py	Wed Apr 29 09:39:21 2009 +0200
     3.2 +++ b/viff/active.py	Thu May 07 11:09:47 2009 +0200
     3.3 @@ -502,6 +502,7 @@
     3.4          result = Share(self, share_x.field)
     3.5          # This is the Deferred we will do processing on.
     3.6          triple = self.get_triple(share_x.field)
     3.7 +        triple.addCallback(gather_shares)
     3.8          self.schedule_callback(triple, finish_mul)
     3.9          # We add the result to the chains in triple.
    3.10          triple.chainDeferred(result)
     4.1 --- a/viff/equality.py	Wed Apr 29 09:39:21 2009 +0200
     4.2 +++ b/viff/equality.py	Thu May 07 11:09:47 2009 +0200
     4.3 @@ -74,7 +74,7 @@
     4.4                  xj = (-1) * (1/Zp(2)) * (bj - 1)
     4.5              return xj
     4.6  
     4.7 -        x = [cj.addCallback(finish, bj) for cj, bj in zip(c, b)]
     4.8 +        x = [self.schedule_callback(cj, finish, bj) for cj, bj in zip(c, b)]
     4.9  
    4.10          # Take the product (this is here the same as the "and") of all
    4.11          # the x'es
     5.1 --- a/viff/passive.py	Wed Apr 29 09:39:21 2009 +0200
     5.2 +++ b/viff/passive.py	Thu May 07 11:09:47 2009 +0200
     5.3 @@ -98,7 +98,7 @@
     5.4                          d = Share(self, share.field, (share.field(peer_id), share))
     5.5                      else:
     5.6                          d = self._expect_share(peer_id, share.field)
     5.7 -                        self.schedule_callback(d, lambda s, peer_id: (s.field(peer_id), s), peer_id)
     5.8 +                        d.addCallback(lambda s, peer_id: (s.field(peer_id), s), peer_id)
     5.9                      deferreds.append(d)
    5.10                  return recombine(deferreds)
    5.11  
     6.1 --- a/viff/runtime.py	Wed Apr 29 09:39:21 2009 +0200
     6.2 +++ b/viff/runtime.py	Thu May 07 11:09:47 2009 +0200
     6.3 @@ -585,8 +585,9 @@
     6.4          The runtime is shut down when all variables are calculated.
     6.5          """
     6.6          dl = DeferredList(vars)
     6.7 -        dl.addCallback(lambda _: self.shutdown())
     6.8 +        self.schedule_callback(dl, lambda _: self.shutdown())
     6.9  
    6.10 +    @increment_pc
    6.11      def schedule_callback(self, deferred, func, *args, **kwargs):
    6.12          """Schedule a callback on a deferred with the correct program
    6.13          counter.
    6.14 @@ -617,7 +618,7 @@
    6.15              finally:
    6.16                  self.program_counter[:] = current_pc
    6.17  
    6.18 -        deferred.addCallback(callback_wrapper, *args, **kwargs)
    6.19 +        return deferred.addCallback(callback_wrapper, *args, **kwargs)
    6.20  
    6.21      @increment_pc
    6.22      def synchronize(self):
    6.23 @@ -832,19 +833,15 @@
    6.24          # profiler here and stop it upon shutdown, but this triggers
    6.25          # http://bugs.python.org/issue1375 since the start and stop
    6.26          # calls are in different stack frames.
    6.27 -        import hotshot
    6.28 -        prof = hotshot.Profile("player-%d.prof" % id)
    6.29 +        import cProfile
    6.30 +        prof = cProfile.Profile()
    6.31          old_run = reactor.run
    6.32          def new_run(*args, **kwargs):
    6.33              print "Starting reactor with profiling"
    6.34              prof.runcall(old_run, *args, **kwargs)
    6.35  
    6.36 -            import sys
    6.37 -            import hotshot.stats
    6.38 -            print "Loading profiling statistics...",
    6.39 -            sys.stdout.flush()
    6.40 -            stats = hotshot.stats.load("player-%d.prof" % id)
    6.41 -            print "done."
    6.42 +            import pstats
    6.43 +            stats = pstats.Stats(prof)
    6.44              print
    6.45              stats.strip_dirs()
    6.46              stats.sort_stats("time", "calls")
     7.1 --- a/viff/test/test_active_runtime.py	Wed Apr 29 09:39:21 2009 +0200
     7.2 +++ b/viff/test/test_active_runtime.py	Thu May 07 11:09:47 2009 +0200
     7.3 @@ -88,7 +88,7 @@
     7.4  
     7.5          double = runtime.double_share_random(T, runtime.threshold,
     7.6                                               2*runtime.threshold, self.Zp)
     7.7 -        double.addCallback(check)
     7.8 +        runtime.schedule_callback(double, check)
     7.9          return double
    7.10  
    7.11      @protocol
    7.12 @@ -116,7 +116,7 @@
    7.13          count, triples = runtime.generate_triples(self.Zp)
    7.14          self.assertEquals(count, runtime.num_players - 2*runtime.threshold)
    7.15  
    7.16 -        triples.addCallback(check)
    7.17 +        runtime.schedule_callback(triples, check)
    7.18          return triples
    7.19  
    7.20  
     8.1 --- a/viff/test/test_basic_runtime.py	Wed Apr 29 09:39:21 2009 +0200
     8.2 +++ b/viff/test/test_basic_runtime.py	Thu May 07 11:09:47 2009 +0200
     8.3 @@ -62,13 +62,13 @@
     8.4          """
     8.5  
     8.6          def verify_program_counter(_):
     8.7 -            self.assertEquals(runtime.program_counter, [0])
     8.8 +            self.assertEquals(runtime.program_counter, [1, 0])
     8.9  
    8.10          d = Deferred()
    8.11          runtime.schedule_callback(d, verify_program_counter)
    8.12  
    8.13          runtime.synchronize()
    8.14 -        self.assertEquals(runtime.program_counter, [1])
    8.15 +        self.assertEquals(runtime.program_counter, [2])
    8.16  
    8.17          # Now trigger verify_program_counter.
    8.18          d.callback(None)
    8.19 @@ -129,8 +129,6 @@
    8.20          d2.callback(None)
    8.21  
    8.22          return gatherResults([d1, d2])
    8.23 -    test_multiple_callbacks.skip = ("TODO: Scheduling callbacks fails to "
    8.24 -                                    "increment program counter!")
    8.25  
    8.26      @protocol
    8.27      def test_multi_send(self, runtime):