[IPython-dev] closing sys.stdout
John Hunter
jdhunter at ace.bsd.uchicago.edu
Tue Sep 19 10:28:12 EDT 2006
Yes, it is possible to cause ipython to dump core!
johnh at jitter:~> ipython
Python 2.4.2 (#1, Feb 23 2006, 12:48:31)
Type "copyright", "credits" or "license" for more information.
IPython 0.7.2 -- An enhanced Interactive Python.
? -> Introduction to IPython's features.
%magic -> Information about IPython's 'magic' % functions.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
In [1]: sys.stdout.close()
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in ?
NameError: name 'sys' is not defined
In [2]: import sys
In [3]: sys.stdout.close()
Segmentation Fault (core dumped)
(solaris 10 x86 architecture)
This came up in a script where I had done
fh = file(fname, 'w')
print >>fh, 'blah'
fh.close()
later when debugging I did
#fh = file(fname, 'w')
fh = sys.stdout
print >>fh, 'blah'
fh.close()
and forgot I had the close in....
I have seen modules, yes really, that explicitly call
sys.stdout.close()
ipython may want to hijack sys.stdout.close to prevent this kind of thing...
JDH
More information about the IPython-dev
mailing list