- When
__exit__
returns True, any exception passed to it is swallowed. - When
__exit__
returns False, the exception is reraised.
def __exit__(self, type, value, traceback):
self.output_pipe.close() # always close the file
if type is not None: # an exception has occurred
os.unlink(...) # remove the file
return False # reraise the exception
You could of course omit the return False
since Python will return None
(which is Falsish) by default.
By the way, is self.output()
an instance of Processor
? If so,
with self.output().open('w') as output:
should be
with self.output() as output:
In any case, it would be nicer if you could arrange for the latter to be the correct syntax. You might have to change __enter__
to:
def __enter__(self):
return self.output_pipe.open('w')