Repository navigation
Expand file tree
/
Copy pathtest_forever.py
More file actions
71 lines (55 loc) · 1.7 KB
/
Copy pathtest_forever.py
File metadata and controls
71 lines (55 loc) · 1.7 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
"""
Test the @forever process decorator which creates server processes.
Copyright (C) Sarah Mount, 2010.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have rceeived a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import os
from functools import reduce
if 'CSP' in os.environ:
if os.environ['CSP'] == 'PROCESSES':
from csp.cspprocess import *
elif os.environ['CSP'] == 'THREADS':
from csp.cspthread import *
else:
from csp.cspprocess import *
else:
from csp.cspprocess import *
del os
import operator
from csp.cspprocess import *
from csp.builtins import Generate, Printer
def test_builtins():
channel, skip = Channel(), Skip()
skip //= Generate(channel), Printer(channel)
@forever
def fact(outchan):
"""
readset = flibble, foo
writeset = outchan, foo
"""
n = 1
f = 1
while True:
if n == 1:
outchan.write(1)
else:
f = reduce(operator.mul, list(range(1, n)))
outchan.write(f)
n += 1
yield
def test_fact():
channel, skip = Channel(), Skip()
skip //= fact(channel), Printer(channel)
if __name__ == '__main__':
# test_builtins()
test_fact()