diff options
author | Cecil Hugh Watson <knoppmyth@gmail.com> | 2010-08-28 21:23:23 (GMT) |
---|---|---|
committer | Cecil Hugh Watson <knoppmyth@gmail.com> | 2010-08-28 21:23:23 (GMT) |
commit | f83117d46d8fc1f6192783371a68607a192c3276 (patch) | |
tree | 21bf30aeb943fe6cb23eb9c62a0ba899de2af0d7 /build_tools/l7/larch0/cli/test.py | |
parent | 69a0137390be9816d5ec5dc9e81d48817a817758 (diff) | |
download | linhes_dev-f83117d46d8fc1f6192783371a68607a192c3276.zip |
Larch 7
Diffstat (limited to 'build_tools/l7/larch0/cli/test.py')
-rwxr-xr-x | build_tools/l7/larch0/cli/test.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/build_tools/l7/larch0/cli/test.py b/build_tools/l7/larch0/cli/test.py new file mode 100755 index 0000000..18e8067 --- /dev/null +++ b/build_tools/l7/larch0/cli/test.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +# +# This is a little script for testing the dispatcher and termination of +# subprocesses. It spawns several levels of itself, each instance just +# outputs an incrementing count until it is terminated. + +import sys, os, time, signal + +try: + import json as serialize +except: + import simplejson as serialize + +def out(text): + sys.stdout.write(serialize.dumps(text) + '\n') + sys.stdout.flush() + +def sigint(num, frame): + """A handler for SIGINT. Tidy up properly and quit. + """ + out("!>INTERRUPTED %d" % level) + exit(1) +signal.signal(signal.SIGINT, sigint) + +level = 3 +while level > 0: + if os.fork(): + break + time.sleep(1) + level -= 1 + +sys.stderr.write('%d: pid=%d ppid=%d pgrp=%d\n' % (level, + os.getpid(), os.getppid(), os.getpgrp())) +sys.stderr.flush() +time.sleep(5) + +n = 0 +while True: + n += 1 + out('--%d: %04d' % (level, n)) + time.sleep(4) + |