comparison 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
comparison
equal deleted inserted replaced
71:ddf533d41c09 72:12df31afb4e1
97 print >> sys.stderr, '%s: %s' % (cmdline[0], err.strerror) 97 print >> sys.stderr, '%s: %s' % (cmdline[0], err.strerror)
98 sys.stderr.flush() 98 sys.stderr.flush()
99 os._exit(0) 99 os._exit(0)
100 self.cfp = os.fdopen(fd, 'w+') 100 self.cfp = os.fdopen(fd, 'w+')
101 try: 101 try:
102 clean_exit = True
103 try: 102 try:
104 # setup env and prompt 103 # setup env and prompt
105 self.sendreceive('source %s\n\n' % rcfile) 104 self.sendreceive('source %s\n\n' % rcfile)
106 for hunk in self.parse(): 105 for hunk in self.parse():
107 # is this line a processing instruction? 106 # is this line a processing instruction?
131 # then its output 130 # then its output
132 ofp.write(tex_escape(output)) 131 ofp.write(tex_escape(output))
133 self.status('\n') 132 self.status('\n')
134 open(self.name + '.run', 'w') 133 open(self.name + '.run', 'w')
135 except: 134 except:
136 clean_exit = False 135 print >> sys.stderr, '(killed)'
136 os.kill(pid, signal.SIGKILL)
137 pid, rc = os.wait()
137 raise 138 raise
138 finally: 139 else:
139 if clean_exit:
140 try: 140 try:
141 output = self.sendreceive('exit\n') 141 output = self.sendreceive('exit\n')
142 if ofp: 142 if ofp:
143 ofp.write(output) 143 ofp.write(output)
144 self.cfp.close() 144 self.cfp.close()
145 except IOError: 145 except IOError:
146 pass 146 pass
147 os.kill(pid, signal.SIGTERM) 147 os.kill(pid, signal.SIGTERM)
148 time.sleep(0.1) 148 pid, rc = os.wait()
149 os.kill(pid, signal.SIGKILL) 149 if rc:
150 pid, rc = os.wait() 150 if os.WIFEXITED(rc):
151 if rc: 151 print >> sys.stderr, '(exit %s)' % os.WEXITSTATUS(rc)
152 if os.WIFEXITED(rc): 152 elif os.WIFSIGNALED(rc):
153 print >> sys.stderr, '(exit %s)' % os.WEXITSTATUS(rc) 153 print >> sys.stderr, '(signal %s)' % os.WTERMSIG(rc)
154 elif os.WIFSIGNALED(rc): 154 return rc
155 print >> sys.stderr, '(signal %s)' % os.WTERMSIG(rc) 155 finally:
156 shutil.rmtree(tmpdir) 156 shutil.rmtree(tmpdir)
157 return rc
158 157
159 def main(path='.'): 158 def main(path='.'):
160 args = sys.argv[1:] 159 args = sys.argv[1:]
161 errs = 0 160 errs = 0
162 if args: 161 if args: