diff --git a/IPython/core/logger.py b/IPython/core/logger.py index e3cb233..99e7ce2 100644 --- a/IPython/core/logger.py +++ b/IPython/core/logger.py @@ -198,7 +198,16 @@ which already exists. But you must first start the logging process with odata = u'\n'.join([u'#[Out]# %s' % s for s in data.splitlines()]) write(u'%s\n' % odata) - self.logfile.flush() + try: + self.logfile.flush() + except OSError: + print("Failed to flush the log file.") + print( + f"Please check that {self.logfname} exists and have the right permissions." + ) + print( + "Also consider turning off the log with `%logstop` to avoid this warning." + ) def logstop(self): """Fully stop logging and close log file.