# HG changeset patch # User Olivier Breuleux # Date 1229555790 18000 # Node ID f8d29730f1462146733c2a0d55fef9515cd18e48 # Parent 6a7f3d83c72b03b6e26b683c9e4c3e8ddfead057 fixed the behavior when raising errors and redirecting stderr diff -r 6a7f3d83c72b -r f8d29730f146 pylearn/dbdict/newstuff.py --- a/pylearn/dbdict/newstuff.py Wed Dec 17 15:39:30 2008 -0500 +++ b/pylearn/dbdict/newstuff.py Wed Dec 17 18:16:30 2008 -0500 @@ -3,6 +3,7 @@ from collections import defaultdict import re, sys, inspect, os, signal, tempfile, shutil, socket +import traceback import sql @@ -272,12 +273,19 @@ signal.signal(signal.SIGINT, self.on_sigterm) return self - def __exit__(self, type, value, traceback): + def __exit__(self, type, value, tb_traceback, save = True): + if type: + try: + raise type, value, tb_traceback + except: + traceback.print_exc() signal.signal(signal.SIGTERM, self.prev_sigterm) signal.signal(signal.SIGINT, self.prev_sigint) self.prev_sigterm = None self.prev_sigint = None - self.save() + if save: + self.save() + return True class StandardChannel(SingleChannel): @@ -305,6 +313,7 @@ return super(StandardChannel, self).__enter__() def __exit__(self, type, value, traceback): + rval = super(StandardChannel, self).__exit__(type, value, traceback, save = False) if self.redirect_stdout: sys.stdout.close() sys.stdout = self.old_stdout @@ -312,7 +321,8 @@ sys.stderr.close() sys.stderr = self.old_stderr os.chdir(self.old_cwd) - return super(StandardChannel, self).__exit__(type, value, traceback) + self.save() + return rval def setup(self): if not os.path.isdir(self.path):