pypy / demo /

The branch 'kill-someobject' does not exist.
Stackless demo.

This example only works on top of a pypy-c compiled with stackless features
and the signal module: --stackless targetpypystandalone --withmod-signal


    pypy-c --start demo.pickle

        Start the computation.  You can interrupt it at any time by
        pressing Ctrl-C; at this point, the state of the computing
        coroutine is saved in demo.pickle.

    pypy-c --resume demo.pickle

        Reload the coroutine from demo.pickle and continue running it.
        (It can be interrupted again with Ctrl-C.)

This demo is documented in detail in pypy/doc/stackless.txt.

    import sys, pickle, signal
    from stackless import coroutine
except ImportError:
    print __doc__

def ackermann(x, y):
    if x == 0:
        return y + 1
    if y == 0:
        return ackermann(x - 1, 1)
    return ackermann(x - 1, ackermann(x, y - 1))

# ____________________________________________________________

main = coroutine.getcurrent()

interrupt_flag = False

def interrupt_handler(*args):
    global interrupt_flag
    interrupt_flag = True

def check():
    if interrupt_flag:

def execute(coro):
    signal.signal(signal.SIGINT, interrupt_handler)
    res = coro.switch()
    if res is None and coro.is_alive:    # interrupted!
        print "interrupted! writing %s..." % (filename,)
        f = open(filename, 'w')
        pickle.dump(coro, f)
        print "done"
        print "result:", res

    operation, filename = sys.argv[1:]
except ValueError:
    print __doc__

if operation == '--start':
    coro = coroutine()
    coro.bind(ackermann, 3, 7)
    print "running from the start..."
elif operation == '--resume':
    print "reloading %s..." % (filename,)
    f = open(filename)
    coro = pickle.load(f)
    print "done, running now..."
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.