From 1cf9ac646b7b0abf3f488db7ebc89eb4b843d836 Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Wed, 1 Jan 2025 11:56:06 -0800 Subject: [PATCH] Ignore OSException along with IOException --- Src/IronPython.Modules/_warnings.cs | 2 +- Src/IronPython/Modules/_fileio.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Src/IronPython.Modules/_warnings.cs b/Src/IronPython.Modules/_warnings.cs index ae37101c8..e343cff9e 100644 --- a/Src/IronPython.Modules/_warnings.cs +++ b/Src/IronPython.Modules/_warnings.cs @@ -260,7 +260,7 @@ internal static void showwarning(CodeContext context, object message, PythonType ((TextWriter)file).Write(text); } // unrecognized file type - warning is lost } - } catch (IOException) { + } catch (Exception ex) when (ex is IOException or OSException) { // invalid file - warning is lost } } diff --git a/Src/IronPython/Modules/_fileio.cs b/Src/IronPython/Modules/_fileio.cs index 5f299b655..e67592af3 100644 --- a/Src/IronPython/Modules/_fileio.cs +++ b/Src/IronPython/Modules/_fileio.cs @@ -305,10 +305,10 @@ public override void close(CodeContext/*!*/ context) { try { flush(context); - } catch (IOException) { - // flushing can fail, esp. if the other half of a pipe is closed - // ignore it because we're closing anyway - } + } catch (IOException) { /* ignore */ } catch (OSException) { /* ignore */ } + // flushing can fail, esp. if the other half of a pipe is closed + // ignore it because we're closing anyway + _closed = true; if (_closefd) {