#!/usr/bin/env python import sys import os import signal import time import yaml import select import empty import thr import cmd_ut import dbg def f_wait_sleep(sec): dbg.out( 'sleep {}'.format( sec ) ) time.sleep( sec ) def f_wait_ev(sec): ev = thr.event_new() dbg.out( 'ev.wait {}'.format( sec ) ) ev.wait( sec ) def f_wait_select(sec): dbg.out( 'select {}'.format( sec ) ) select.select( [ sys.stdin ], [], [], sec ) def test(s_new, stop, s_wait, sec, gc, n): dbg.out( 's_new={} stop={} s_wait={} sec={} gc={} n={}'.format( s_new, stop, s_wait, sec, gc, n ) ) thr_gc = None if gc: thr_gc = thr.gc_new() f_new = eval( s_new ) f_wait = eval( s_wait ) def targ(): f_wait( sec ) ths = [] for i in range( n ): th = f_new( targ, gc=thr_gc ) th.start() ths.append( th ) time.sleep( 0.5 ) if stop: for th in ths: dbg.out( '>stop' ) th.stop() dbg.out( 'gc.stop' ) thr_gc.stop() dbg.out( '= len( args ): return False # round arg = args[ j ] arg.i += 1 if arg.i < arg.n: return True arg.i = 0 return cnt_up( j + 1 ) confs = [] while True: conf = dict( map( lambda arg: ( arg.name, arg.vals[ arg.i ] ), args ) ) confs.append( conf ) if not cnt_up(0): break return confs def run(): s = ' '.join( sys.argv[ 1 : ] ) if s: dic = yaml.load( s ) test( **dic ) return confs = make_confs() for dic in confs: s = yaml.dump( dic, default_flow_style=True ).strip() cmd = '{} "{}"'.format( sys.argv[ 0 ], s ) #dbg.out( cmd ) proc = cmd_ut.proc_new( cmd ) #sec = dic.get( 'sec' ) time.sleep( 2.0 ) #proc.kill() os.kill( proc.proc.pid, signal.SIGINT ) #os.killpg( proc.proc.pid, signal.SIGINT ) dbg.out( 'kill SIGINT' ) proc.wait() dbg.out( 'wait ok\n' ) if __name__ == "__main__": run() # EOF