Only call self.stream.close() when not using an alternative stream to avoid
AttributeError: '_ReplOutput' object has no attribute 'close'