##// END OF EJS Templates
- Small fix to pexpect to prevent unhandled exceptions at Python shutdown...
fperez -
Show More
@@ -45,6 +45,41 b' Interactive script runner, type: %s'
45 runner [opts] script_name
45 runner [opts] script_name
46 """
46 """
47
47
48 def pexpect_monkeypatch():
49 """Patch pexpect to prevent unhandled exceptions at VM teardown.
50
51 Calling this function will monkeypatch the pexpect.spawn class and modify
52 its __del__ method to make it more robust in the face of failures that can
53 occur if it is called when the Python VM is shutting down.
54
55 Since Python may fire __del__ methods arbitrarily late, it's possible for
56 them to execute during the teardown of the Python VM itself. At this
57 point, various builtin modules have been reset to None. Thus, the call to
58 self.close() will trigger an exception because it tries to call os.close(),
59 and os is now None.
60 """
61
62 if pexpect.__version__[:3] >= '2.2':
63 # No need to patch, fix is already the upstream version.
64 return
65
66 def __del__(self):
67 """This makes sure that no system resources are left open.
68 Python only garbage collects Python objects. OS file descriptors
69 are not Python objects, so they must be handled explicitly.
70 If the child file descriptor was opened outside of this class
71 (passed to the constructor) then this does not close it.
72 """
73 if not self.closed:
74 try:
75 self.close()
76 except AttributeError:
77 pass
78
79 pexpect.spawn.__del__ = __del__
80
81 pexpect_monkeypatch()
82
48 # The generic runner class
83 # The generic runner class
49 class InteractiveRunner(object):
84 class InteractiveRunner(object):
50 """Class to run a sequence of commands through an interactive program."""
85 """Class to run a sequence of commands through an interactive program."""
@@ -1,3 +1,9 b''
1 2007-02-18 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/irunner.py (pexpect_monkeypatch): patch pexpect to
4 protect against exceptions at Python shutdown time. Patch
5 sumbmitted to upstream.
6
1 2007-02-14 Walter Doerwald <walter@livinglogic.de>
7 2007-02-14 Walter Doerwald <walter@livinglogic.de>
2
8
3 * IPython/Extensions/ibrowse.py: If entering the first object level
9 * IPython/Extensions/ibrowse.py: If entering the first object level
General Comments 0
You need to be logged in to leave comments. Login now