4
This example only works on top of a pypy-c compiled with stackless features
7
translate.py --stackless targetpypystandalone --withmod-signal
11
pypy-c pickle_coroutine.py --start demo.pickle
13
Start the computation. You can interrupt it at any time by
14
pressing Ctrl-C; at this point, the state of the computing
15
coroutine is saved in demo.pickle.
17
pypy-c pickle_coroutine.py --resume demo.pickle
19
Reload the coroutine from demo.pickle and continue running it.
20
(It can be interrupted again with Ctrl-C.)
22
This demo is documented in detail in pypy/doc/stackless.txt.
26
import sys, pickle, signal
27
from stackless import coroutine
38
return ackermann(x - 1, 1)
39
return ackermann(x - 1, ackermann(x, y - 1))
41
# ____________________________________________________________
43
main = coroutine.getcurrent()
44
sys.setrecursionlimit(100000)
46
interrupt_flag = False
48
def interrupt_handler(*args):
58
signal.signal(signal.SIGINT, interrupt_handler)
60
if res is None and coro.is_alive: # interrupted!
61
print "interrupted! writing %s..." % (filename,)
62
f = open(filename, 'w')
70
operation, filename = sys.argv[1:]
75
if operation == '--start':
77
coro.bind(ackermann, 3, 7)
78
print "running from the start..."
80
elif operation == '--resume':
81
print "reloading %s..." % (filename,)
85
print "done, running now..."