From 5b318cae7d3c425d9bf56d1e1299f043b5a3c14a 2015-10-27 15:33:07 From: John Kirkham Date: 2015-10-27 15:33:07 Subject: [PATCH] IPython/utils/io.py: Make sure `devnull` is closed at exit to avoid a `ResourceWarning` being raised by Python 3. --- diff --git a/IPython/utils/io.py b/IPython/utils/io.py index 5b0fdb2..2ba3fd5 100644 --- a/IPython/utils/io.py +++ b/IPython/utils/io.py @@ -10,6 +10,7 @@ from __future__ import print_function from __future__ import absolute_import +import atexit import os import sys import tempfile @@ -73,6 +74,7 @@ class IOStream: # setup stdin/stdout/stderr to sys.stdin/sys.stdout/sys.stderr devnull = open(os.devnull, 'w') +atexit.register(devnull.close) stdin = IOStream(sys.stdin, fallback=devnull) stdout = IOStream(sys.stdout, fallback=devnull) stderr = IOStream(sys.stderr, fallback=devnull)