Mercurial > hgbook
diff en/examples/run-example @ 72:12df31afb4e1
Propagate exceptions more correctly.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Tue, 29 Aug 2006 22:34:03 -0700 |
parents | ddf533d41c09 |
children | 9604dd885616 |
line wrap: on
line diff
--- a/en/examples/run-example Tue Aug 29 22:25:18 2006 -0700 +++ b/en/examples/run-example Tue Aug 29 22:34:03 2006 -0700 @@ -99,7 +99,6 @@ os._exit(0) self.cfp = os.fdopen(fd, 'w+') try: - clean_exit = True try: # setup env and prompt self.sendreceive('source %s\n\n' % rcfile) @@ -133,10 +132,11 @@ self.status('\n') open(self.name + '.run', 'w') except: - clean_exit = False + print >> sys.stderr, '(killed)' + os.kill(pid, signal.SIGKILL) + pid, rc = os.wait() raise - finally: - if clean_exit: + else: try: output = self.sendreceive('exit\n') if ofp: @@ -144,17 +144,16 @@ self.cfp.close() except IOError: pass - os.kill(pid, signal.SIGTERM) - time.sleep(0.1) - os.kill(pid, signal.SIGKILL) - pid, rc = os.wait() - if rc: - if os.WIFEXITED(rc): - print >> sys.stderr, '(exit %s)' % os.WEXITSTATUS(rc) - elif os.WIFSIGNALED(rc): - print >> sys.stderr, '(signal %s)' % os.WTERMSIG(rc) + os.kill(pid, signal.SIGTERM) + pid, rc = os.wait() + if rc: + if os.WIFEXITED(rc): + print >> sys.stderr, '(exit %s)' % os.WEXITSTATUS(rc) + elif os.WIFSIGNALED(rc): + print >> sys.stderr, '(signal %s)' % os.WTERMSIG(rc) + return rc + finally: shutil.rmtree(tmpdir) - return rc def main(path='.'): args = sys.argv[1:]