hgbook
changeset 72:12df31afb4e1
Propagate exceptions more correctly.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Tue Aug 29 22:34:03 2006 -0700 (2006-08-29) |
parents | ddf533d41c09 |
children | 9604dd885616 |
files | en/examples/run-example |
line diff
1.1 --- a/en/examples/run-example Tue Aug 29 22:25:18 2006 -0700 1.2 +++ b/en/examples/run-example Tue Aug 29 22:34:03 2006 -0700 1.3 @@ -99,7 +99,6 @@ 1.4 os._exit(0) 1.5 self.cfp = os.fdopen(fd, 'w+') 1.6 try: 1.7 - clean_exit = True 1.8 try: 1.9 # setup env and prompt 1.10 self.sendreceive('source %s\n\n' % rcfile) 1.11 @@ -133,10 +132,11 @@ 1.12 self.status('\n') 1.13 open(self.name + '.run', 'w') 1.14 except: 1.15 - clean_exit = False 1.16 + print >> sys.stderr, '(killed)' 1.17 + os.kill(pid, signal.SIGKILL) 1.18 + pid, rc = os.wait() 1.19 raise 1.20 - finally: 1.21 - if clean_exit: 1.22 + else: 1.23 try: 1.24 output = self.sendreceive('exit\n') 1.25 if ofp: 1.26 @@ -144,17 +144,16 @@ 1.27 self.cfp.close() 1.28 except IOError: 1.29 pass 1.30 - os.kill(pid, signal.SIGTERM) 1.31 - time.sleep(0.1) 1.32 - os.kill(pid, signal.SIGKILL) 1.33 - pid, rc = os.wait() 1.34 - if rc: 1.35 - if os.WIFEXITED(rc): 1.36 - print >> sys.stderr, '(exit %s)' % os.WEXITSTATUS(rc) 1.37 - elif os.WIFSIGNALED(rc): 1.38 - print >> sys.stderr, '(signal %s)' % os.WTERMSIG(rc) 1.39 + os.kill(pid, signal.SIGTERM) 1.40 + pid, rc = os.wait() 1.41 + if rc: 1.42 + if os.WIFEXITED(rc): 1.43 + print >> sys.stderr, '(exit %s)' % os.WEXITSTATUS(rc) 1.44 + elif os.WIFSIGNALED(rc): 1.45 + print >> sys.stderr, '(signal %s)' % os.WTERMSIG(rc) 1.46 + return rc 1.47 + finally: 1.48 shutil.rmtree(tmpdir) 1.49 - return rc 1.50 1.51 def main(path='.'): 1.52 args = sys.argv[1:]