File: factorial.py

package info (click to toggle)
circuits 3.2.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,980 kB
  • sloc: python: 17,583; javascript: 3,226; makefile: 100
file content (32 lines) | stat: -rwxr-xr-x 644 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python

from time import sleep

from circuits import Component, Debugger, Event, Timer, Worker, task


def factorial(n):
    x = 1
    for i in range(1, (n + 1)):
        x = x * (i + 1)
        sleep(1)  # deliberate!
    return x


class App(Component):
    def init(self, *args, **kwargs):
        Worker(process=True).register(self)

    def foo(self):
        print('Foo!')

    def started(self, component):
        Timer(1, Event.create('foo'), persist=True).register(self)
        x = yield self.call(task(factorial, 10))
        print(f'{x.value:d}')
        self.stop()


app = App()
Debugger().register(app)
app.run()