#!/usr/bin/env python
from __future__ import generators
if __debug__:
    from SimPy.SimulationStep import *
else:
    from SimPy.Simulation import *

def callbackTimeTrace():
    """Prints event times
    """
    print "at time=%s"%now()
    
def callbackUserControl():
    """Allows user to control stepping
    """
    a=raw_input("[Time=%s] Select one: End run (e), Continue stepping (s), Run to end (r)= "%now())
    if a=="e":
        stopSimulation()
    elif a=="s":
        return
    else:
        stopStepping()
        
class Man(Process):
    def walk(self):
        print "got up"
        yield hold,self,1
        print "got to door"
        yield hold,self,10
        print "got to mail box"
        yield hold,self,10
        print "got home again"
        
#trace event times
initialize()
otto=Man()
activate(otto,otto.walk())
if __debug__:
    startStepping()
    simulate(callback=callbackTimeTrace,until=100)
else:
    simulate(until=100)

#allow user control
initialize()
otto=Man()
activate(otto,otto.walk())
if __debug__:
    startStepping()
    simulate(callback=callbackUserControl,until=100)
else:
    simulate(until=100)

