# -*- Mode: Python; tab-width: 4 -*- # newpotato.py # # a script for testing the coroutine module, based on Sam's demo potato.py # # With a previous version (1.11) of the coroutine module, this script would # dump core if given a number # larger or equal to 4. Now, "python newpotato.py 10000 | head" # will cause a "Broken Pipe Error", although "python newpotato.py 10000" # works fine. - martinb 2000/04/23 import coroutine import sys def hot_potato_1 (n): global co2 while 1: print "co1: n is", n if type(n) != type(1): n = n[0] print "co1: using", n if n == 0: coroutine.main ('done') else: args = ((n-1, 0,),) n = coroutine.resume (co2, args) def hot_potato_2 (n): global co1 while 1: print "co2: n is", n if type(n) != type(1): n = n[0] print "co2: using", n if n == 0: coroutine.main ('done') else: args = (n-1,) n = coroutine.resume (co1, args) co1 = coroutine.new (hot_potato_1) co2 = coroutine.new (hot_potato_2) print coroutine.resume (co1, (int(sys.argv[1]),))