##// END OF EJS Templates
Fix bug where atexit operations were only done if readline was present.
Fernando Perez -
Show More
@@ -20,6 +20,7 b' from __future__ import absolute_import'
20 import __builtin__
20 import __builtin__
21 import __future__
21 import __future__
22 import abc
22 import abc
23 import atexit
23 import codeop
24 import codeop
24 import exceptions
25 import exceptions
25 import new
26 import new
@@ -276,6 +277,7 b' class InteractiveShell(Configurable, Magic):'
276 self.init_plugin_manager()
277 self.init_plugin_manager()
277 self.init_payload()
278 self.init_payload()
278 self.hooks.late_startup_hook()
279 self.hooks.late_startup_hook()
280 atexit.register(self.atexit_operations)
279
281
280 @classmethod
282 @classmethod
281 def instance(cls, *args, **kwargs):
283 def instance(cls, *args, **kwargs):
@@ -1605,8 +1607,6 b' class InteractiveShell(Configurable, Magic):'
1605 self.has_readline = True
1607 self.has_readline = True
1606 self.readline = readline
1608 self.readline = readline
1607 sys.modules['readline'] = readline
1609 sys.modules['readline'] = readline
1608 import atexit
1609 ###
1610
1610
1611 from IPython.core.completer import IPCompleter
1611 from IPython.core.completer import IPCompleter
1612 self.Completer = IPCompleter(self,
1612 self.Completer = IPCompleter(self,
@@ -1620,6 +1620,9 b' class InteractiveShell(Configurable, Magic):'
1620
1620
1621 # Platform-specific configuration
1621 # Platform-specific configuration
1622 if os.name == 'nt':
1622 if os.name == 'nt':
1623 # FIXME - check with Frederick to see if we can harmonize
1624 # naming conventions with pyreadline to avoid this
1625 # platform-dependent check
1623 self.readline_startup_hook = readline.set_pre_input_hook
1626 self.readline_startup_hook = readline.set_pre_input_hook
1624 else:
1627 else:
1625 self.readline_startup_hook = readline.set_startup_hook
1628 self.readline_startup_hook = readline.set_startup_hook
@@ -1666,8 +1669,9 b' class InteractiveShell(Configurable, Magic):'
1666 except IOError:
1669 except IOError:
1667 pass # It doesn't exist yet.
1670 pass # It doesn't exist yet.
1668
1671
1669 atexit.register(self.atexit_operations)
1672 # If we have readline, we want our history saved upon ipython
1670 del atexit
1673 # exiting.
1674 atexit.register(self.savehist)
1671
1675
1672 # Configure auto-indent for all platforms
1676 # Configure auto-indent for all platforms
1673 self.set_autoindent(self.autoindent)
1677 self.set_autoindent(self.autoindent)
@@ -2328,14 +2332,17 b' class InteractiveShell(Configurable, Magic):'
2328 #-------------------------------------------------------------------------
2332 #-------------------------------------------------------------------------
2329 # Things related to IPython exiting
2333 # Things related to IPython exiting
2330 #-------------------------------------------------------------------------
2334 #-------------------------------------------------------------------------
2331
2332 def atexit_operations(self):
2335 def atexit_operations(self):
2333 """This will be executed at the time of exit.
2336 """This will be executed at the time of exit.
2334
2337
2335 Saving of persistent data should be performed here.
2338 Cleanup operations and saving of persistent data that is done
2336 """
2339 unconditionally by IPython should be performed here.
2337 self.savehist()
2338
2340
2341 For things that may depend on startup flags or platform specifics (such
2342 as having readline or not), register a separate atexit function in the
2343 code that has the appropriate information, rather than trying to
2344 clutter
2345 """
2339 # Cleanup all tempfiles left around
2346 # Cleanup all tempfiles left around
2340 for tfile in self.tempfiles:
2347 for tfile in self.tempfiles:
2341 try:
2348 try:
@@ -289,7 +289,7 b' class TerminalInteractiveShell(InteractiveShell):'
289 # We must ensure that our completer is back in place.
289 # We must ensure that our completer is back in place.
290
290
291 if self.has_readline:
291 if self.has_readline:
292 self.set_completer()
292 self.set_readline_completer()
293
293
294 try:
294 try:
295 line = raw_input_original(prompt).decode(self.stdin_encoding)
295 line = raw_input_original(prompt).decode(self.stdin_encoding)
General Comments 0
You need to be logged in to leave comments. Login now