<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import sys <EOL> from time import time <EOL> from traceback import format_exc <EOL> from signal import SIGINT , SIGTERM <EOL> from circuits import ipc , handler , Event , Component <EOL> def log ( msg , * args , ** kwargs ) : <EOL> sys . stderr . write ( "<STR_LIT>" . format ( msg . format ( * args ) , kwargs . get ( "<STR_LIT:n>" , "<STR_LIT:\n>" ) ) ) <EOL> sys . stderr . flush ( ) <EOL> def error ( e ) : <EOL> log ( "<STR_LIT>" , e ) <EOL> log ( format_exc ( ) ) <EOL> def status ( msg , * args ) : <EOL> log ( "<STR_LIT>" , msg . format ( * args ) , n = "<STR_LIT>" ) <EOL> class ping ( Event ) : <EOL> """<STR_LIT>""" <EOL> class pong ( Event ) : <EOL> """<STR_LIT>""" <EOL> class Child ( Component ) : <EOL> def ping ( self , ts ) : <EOL> self . fire ( ipc ( pong ( ts , time ( ) ) ) ) <EOL> class App ( Component ) : <EOL> def init ( self ) : <EOL> self . events = <NUM_LIT:0> <EOL> self . stime = time ( ) <EOL> Child ( ) . start ( process = True , link = self ) <EOL> def ready ( self , * args ) : <EOL> self . fire ( ipc ( ping ( time ( ) ) ) ) <EOL> def pong ( self , ts1 , ts2 ) : <EOL> latency = ( ts2 - ts1 ) * <NUM_LIT> <EOL> status ( <EOL> "<STR_LIT>" . format ( <EOL> int ( self . events / ( time ( ) - self . stime ) ) , <EOL> latency <EOL> ) <EOL> ) <EOL> self . fire ( ipc ( ping ( time ( ) ) ) ) <EOL> def signal ( self , signo , stack ) : <EOL> if signo in [ SIGINT , SIGTERM ] : <EOL> raise SystemExit ( <NUM_LIT:0> ) <EOL> @ handler ( ) <EOL> def on_event ( self , * args , ** kwargs ) : <EOL> self . events += <NUM_LIT:1> <EOL> App ( ) . run ( ) </s>
