daily pastebin goal
25%
SHARE
TWEET

Untitled

a guest Aug 18th, 2016 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import time
  2. from circuits import BaseComponent, Worker, Debugger, task, handler
  3.  
  4. class App(BaseComponent):
  5.     def factorial(self, n):
  6.         time.sleep(.2)
  7.         if n > 1:
  8.             nn = yield from self.call(task(self.factorial, n-1))
  9.             return n * nn.value
  10.         else:
  11.             return 1
  12.  
  13.     @handler("started")
  14.     def started(self, *args):
  15.         Worker().register(self)
  16.         rv = yield self.call(task(self.factorial, 5))
  17.         print(rv.value)
  18.         self.stop()
  19.  
  20. (App() + Debugger()).run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top