Skip to content
This repository

add qt config option to clear_on_kernel_restart #1681

Merged
merged 4 commits into from almost 2 years ago

4 participants

Paul Ivanov Fernando Perez Thomas Kluyver Min RK
Paul Ivanov
Collaborator
ivanov commented May 01, 2012

Previously, restarting a kernel in the qtconsole always cleared the
entire session. Since qtconsole has a %clear command, it makes sense to
allow users to decouple the two activities - the restarting of kernels,
and clearing the console. This PR adds a configuration option which allows for the restarting of kernels without losing console history. The default value for clear_on_kernel_restart is set to True to stay consistent with the way things worked before this functionality was added.

To test, run:

ipython qtconsole --IPythonWidget.clear_on_kernel_restart=False

Here's what it looks like when the user restarts the kernel on In[3]:

Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
Type "copyright", "credits" or "license" for more information.

IPython 0.13.dev -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
%guiref   -> A brief reference about the graphical user interface.

In [1]: 0x42
Out[1]: 66

In [2]: 042
Out[2]: 34

In [3]: # restarting kernel...
#------------------------------------------

In [1]:
Paul Ivanov
Collaborator
ivanov commented May 01, 2012

I could use feedback if I should go ahead and remove the messagebox logic on after line 522 to also use this new option.

Fernando Perez
Owner
fperez commented May 01, 2012

No time to review right now (gotta catch a flight early tomorrow, will be offline for a bit), but I wanted to say thank you for this. I've been wanting this for a long time.

Paul Ivanov add qt config option to clear_on_kernel_restart
Previously, restarting a kernel in the qtconsole always cleared the
entire session. Since qtconsole has a %clear command, it makes sense to
allow users to decouple the two activities - the restarting of kernels,
and clearing the console.  This commit adds a configuration option which
allows for the restarting of kernels without losing console history. The
default value for clear_on_kernel_restart is set to True to stay
consistent with the way things worked before this functionality was
added.

To test, run:

    ipython qtconsole --IPythonWidget.clear_on_kernel_restart=False

Here's what it looks like when the user restarts the kernel on In[3]:

 Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
 Type "copyright", "credits" or "license" for more information.

 IPython 0.13.dev -- An enhanced Interactive Python.
 ?         -> Introduction and overview of IPython's features.
 %quickref -> Quick reference.
 help      -> Python's own help system.
 object?   -> Details about 'object', use 'object??' for extra details.
 %guiref   -> A brief reference about the graphical user interface.

 In [1]: 0x42
 Out[1]: 66

 In [2]: 042
 Out[2]: 34

 In [3]: # restarting kernel...
 #------------------------------------------
 In [1]:
90356a4
Thomas Kluyver
Collaborator

IIRC, we're using a rich text widget - is it easy to draw a proper horizontal line, rather than an ASCII art -----?

Paul Ivanov
Collaborator
ivanov commented May 04, 2012

ok, now using html <hr> instead of ASCII ----, took me a bit to get to the bottom of it, so @takluyver better be happy with the results! ;)

Thomas Kluyver
Collaborator

Thanks Paul, I've just tested, and I like the way it's looking now.

Min RK
Owner
minrk commented May 13, 2012

Looks good to me. Any reason not to merge?

Paul Ivanov
Collaborator
ivanov commented May 14, 2012

@minrk, actually, yeah, hang on, found a minor problem with this

Paul Ivanov move clear_on_kernel_restart back inside reset()
I originally made a new method (reset_on_restart) to accommodate this
new functionality, but it turns out I ended up needing to replicate
almost everything that reset() already does inside this new method. In
particular, reset_on_restart did not work properly when restarting a
kernel that was in debug mode.

Everything should now work, and we don't have another method to deal
with.
a9c55d5
Paul Ivanov
Collaborator
ivanov commented May 14, 2012

ok @minrk and @takluyver - I think it's ready to merge again:

I originally made a new method (reset_on_restart) to accommodate this
new functionality, but it turns out I ended up needing to replicate
almost everything that reset() already does inside this new method. In
particular, reset_on_restart did not work properly when restarting a
kernel that was in debug mode.

Everything should now work, and we don't have another method to deal
with.

Paul Ivanov
Collaborator
ivanov commented May 14, 2012

having second thoughts about calling the parameter force, does clear make more sense? or force_clear?

Min RK
Owner
minrk commented May 14, 2012

clear seems most appropriate, since that's the switch you are flipping.

Thomas Kluyver
Collaborator

I agree that clear makes more sense - force sounds like "don't ask for confirmation".

Other than that, it looks good, and I think putting it inside the reset method makes sense. I assume you've tested it again in both modes.

Paul Ivanov
Collaborator
ivanov commented May 14, 2012

ok, thanks for being patient with me, guys. Renamed it to clear, ready to merge, and yes, tested it in both modes.

Paul Ivanov ivanov merged commit cffb287 into from May 15, 2012
Paul Ivanov ivanov closed this May 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 4 unique commits by 1 author.

May 01, 2012
Paul Ivanov add qt config option to clear_on_kernel_restart
Previously, restarting a kernel in the qtconsole always cleared the
entire session. Since qtconsole has a %clear command, it makes sense to
allow users to decouple the two activities - the restarting of kernels,
and clearing the console.  This commit adds a configuration option which
allows for the restarting of kernels without losing console history. The
default value for clear_on_kernel_restart is set to True to stay
consistent with the way things worked before this functionality was
added.

To test, run:

    ipython qtconsole --IPythonWidget.clear_on_kernel_restart=False

Here's what it looks like when the user restarts the kernel on In[3]:

 Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
 Type "copyright", "credits" or "license" for more information.

 IPython 0.13.dev -- An enhanced Interactive Python.
 ?         -> Introduction and overview of IPython's features.
 %quickref -> Quick reference.
 help      -> Python's own help system.
 object?   -> Details about 'object', use 'object??' for extra details.
 %guiref   -> A brief reference about the graphical user interface.

 In [1]: 0x42
 Out[1]: 66

 In [2]: 042
 Out[2]: 34

 In [3]: # restarting kernel...
 #------------------------------------------
 In [1]:
90356a4
May 04, 2012
Paul Ivanov use html <hr> instead of ascii one 4209a8d
May 14, 2012
Paul Ivanov move clear_on_kernel_restart back inside reset()
I originally made a new method (reset_on_restart) to accommodate this
new functionality, but it turns out I ended up needing to replicate
almost everything that reset() already does inside this new method. In
particular, reset_on_restart did not work properly when restarting a
kernel that was in debug mode.

Everything should now work, and we don't have another method to deal
with.
a9c55d5
Paul Ivanov rename reset parameter to 'clear' for clarity 0b63550
This page is out of date. Refresh to see the latest.
30  IPython/frontend/qt/console/frontend_widget.py
@@ -95,6 +95,9 @@ class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):
95 95
     enable_calltips = Bool(True, config=True,
96 96
         help="Whether to draw information calltips on open-parentheses.")
97 97
 
  98
+    clear_on_kernel_restart = Bool(True, config=True,
  99
+        help="Whether to clear the console when the kernel is restarted")
  100
+
98 101
     # Emitted when a user visible 'execute_request' has been submitted to the
99 102
     # kernel from the FrontendWidget. Contains the code to be executed.
100 103
     executing = QtCore.Signal(object)
@@ -516,6 +519,8 @@ def _handle_shutdown_reply(self, msg):
516 519
                     if reply == QtGui.QMessageBox.Yes:
517 520
                         self.exit_requested.emit(self)
518 521
                 else:
  522
+                    # XXX: remove message box in favor of using the
  523
+                    # clear_on_kernel_restart setting?
519 524
                     reply = QtGui.QMessageBox.question(self, title,
520 525
                         "Kernel has been reset. Clear the Console?",
521 526
                         QtGui.QMessageBox.Yes,QtGui.QMessageBox.No)
@@ -529,7 +534,7 @@ def _started_channels(self):
529 534
         """ Called when the KernelManager channels have started listening or
530 535
             when the frontend is assigned an already listening KernelManager.
531 536
         """
532  
-        self.reset()
  537
+        self.reset(clear=True)
533 538
 
534 539
     #---------------------------------------------------------------------------
535 540
     # 'FrontendWidget' public interface
@@ -563,9 +568,13 @@ def interrupt_kernel(self):
563 568
             self._append_plain_text('Kernel process is either remote or '
564 569
                                     'unspecified. Cannot interrupt.\n')
565 570
 
566  
-    def reset(self):
567  
-        """ Resets the widget to its initial state. Similar to ``clear``, but
568  
-            also re-writes the banner and aborts execution if necessary.
  571
+    def reset(self, clear=False):
  572
+        """ Resets the widget to its initial state if ``clear`` parameter or
  573
+        ``clear_on_kernel_restart`` configuration setting is True, otherwise
  574
+        prints a visual indication of the fact that the kernel restarted, but
  575
+        does not clear the traces from previous usage of the kernel before it
  576
+        was restarted.  With ``clear=True``, it is similar to ``%clear``, but
  577
+        also re-writes the banner and aborts execution if necessary.
569 578
         """
570 579
         if self._executing:
571 580
             self._executing = False
@@ -573,8 +582,15 @@ def reset(self):
573 582
         self._reading = False
574 583
         self._highlighter.highlighting_on = False
575 584
 
576  
-        self._control.clear()
577  
-        self._append_plain_text(self.banner)
  585
+        if self.clear_on_kernel_restart or clear:
  586
+            self._control.clear()
  587
+            self._append_plain_text(self.banner)
  588
+        else:
  589
+            self._append_plain_text("# restarting kernel...")
  590
+            self._append_html("<hr><br>")
  591
+            # XXX: Reprinting the full banner may be too much, but once #1680 is
  592
+            # addressed, that will mitigate it.
  593
+            #self._append_plain_text(self.banner)
578 594
         # update output marker for stdout/stderr, so that startup
579 595
         # messages appear after banner:
580 596
         self._append_before_prompt_pos = self._get_cursor().position()
@@ -693,7 +709,7 @@ def _process_execute_error(self, msg):
693 709
             self._append_plain_text(traceback)
694 710
 
695 711
     def _process_execute_ok(self, msg):
696  
-        """ Process a reply for a successful execution equest.
  712
+        """ Process a reply for a successful execution request.
697 713
         """
698 714
         payload = msg['content']['payload']
699 715
         for item in payload:
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.