Skip to content

add qt config option to clear_on_kernel_restart#1681

Merged
ivanov merged 4 commits into
ipython:masterfrom
ivanov:optionally-clear-on-restart
May 16, 2012
Merged

add qt config option to clear_on_kernel_restart#1681
ivanov merged 4 commits into
ipython:masterfrom
ivanov:optionally-clear-on-restart

Conversation

@ivanov
Copy link
Copy Markdown
Member

@ivanov ivanov commented May 2, 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]:

@ivanov
Copy link
Copy Markdown
Member Author

ivanov commented May 2, 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.

@fperez
Copy link
Copy Markdown
Member

fperez commented May 2, 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.

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]:
@takluyver
Copy link
Copy Markdown
Member

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

@ivanov
Copy link
Copy Markdown
Member Author

ivanov commented May 5, 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! ;)

@takluyver
Copy link
Copy Markdown
Member

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

@minrk
Copy link
Copy Markdown
Member

minrk commented May 13, 2012

Looks good to me. Any reason not to merge?

@ivanov
Copy link
Copy Markdown
Member Author

ivanov commented May 14, 2012

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

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.
@ivanov
Copy link
Copy Markdown
Member Author

ivanov commented May 15, 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.

@ivanov
Copy link
Copy Markdown
Member Author

ivanov commented May 15, 2012

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

@minrk
Copy link
Copy Markdown
Member

minrk commented May 15, 2012

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

@takluyver
Copy link
Copy Markdown
Member

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.

@ivanov
Copy link
Copy Markdown
Member Author

ivanov commented May 15, 2012

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

ivanov added a commit that referenced this pull request May 16, 2012
add qt config option to clear_on_kernel_restart.

This allows for restarting kernels without clearing the qtconsole,
while leaving a visible indication that the kernel has restarted.
@ivanov ivanov merged commit cffb287 into ipython:master May 16, 2012
@SamuelDeleglise
Copy link
Copy Markdown

Hi all,

I am not sure if this is the best place for this comment, but I will try anyway:
I use ipython notebook (IPython 2.1.0) on windows. The options are interpreted correctly (for instance launching the notebook with --IPythonWidget.confirm_restart=False has the correct effect), however, the option IPythonWidget.clear_on_kernel_restart=True has no effect. This is particularly cumbersome since there is a small bug associated with restarting the kernel without clearing the screen: the console doesn't scroll down to the first command prompt (it scrolls down only to the horizontal line, and I have to hit enter once to have it scroll to the new command prompt).

Are these 2 bugs (scrolling problem + no way to disable clear_on_kernel_restart) windows related and is there a way to solve them? I use the pythonxy distribution and these problems have been appearing on all the computers I have tried so far.

Thanks for your help,
Samuel

@takluyver
Copy link
Copy Markdown
Member

Hi Samuel - it looks like the code to check that option was taken out somewhere along the line. If you can work out where it should be checked, please make a pull request to do so.

@SamuelDeleglise
Copy link
Copy Markdown

Hi Thomas, Thanks for the quick reply, I have been looking around in the code, especially in
IPython\qt\console\frontend_widget.py
Hoping for a commented line or something as trivial as that, but after one hour of digging, I must admit my incompetence. I tried to add a self.reset(True) in restart_kernel(..) but I have the feeling it's actually restarting the kernel twice since the restart command is taking very long...
Sorry for not being more helpful,
Cheers,
Samuel

@takluyver
Copy link
Copy Markdown
Member

It certainly looks like sticking self.reset(True) in the right part of restart_kernel (about where it adds the "Restarting kernel..." HTML) should work.

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
add qt config option to clear_on_kernel_restart.

This allows for restarting kernels without clearing the qtconsole,
while leaving a visible indication that the kernel has restarted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants