Skip to content

Commit 8fd57f6

Browse files
committed
catch all exceptions when trying to close the standard streams
1 parent 6991239 commit 8fd57f6

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

graalpython/lib-graalpython/pyio_patches.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,22 @@ def open(*args, **kwargs):
9595
sys.stderr.mode = "w"
9696
sys.__stderr__ = sys.stderr
9797

98+
99+
# Try to close the std streams when we exit
98100
import atexit
99-
atexit.register(sys.stdout.close)
100-
atexit.register(sys.stderr.close)
101+
def close_stdouts(so=sys.stdout, se=sys.stderr):
102+
try:
103+
so.close()
104+
except:
105+
pass
106+
try:
107+
se.close()
108+
except:
109+
pass
110+
111+
112+
atexit.register(close_stdouts)
113+
101114

102115
# See comment in _pyio.py. This method isn't strictly necessary and is provided
103116
# on CPython for performance. Because it goes through memoryview, it is slower

0 commit comments

Comments
 (0)