Repository: ipython/ipython

Issue:
[qtconsole] %hist doesn't show anything in qtconsole
I have built rc2 on Windows XP and while the qtconsole works fine for the most part, %hist does not show any history in the qtconsole.



Discussion:
A bare %hist will show history from the start of the session, so be sure you've entered a few commands before trying it.

Does it produce any output after you type %hist? Any error messages? Do you get the next prompt? If you start `ipython qtconsole` (or whatever the command is in Windows) from a command prompt, do you get any error messages there? Does %hist still work in terminal IPython?

Yes. I type in a few command to see if they appear in the %hist. The 
terminal version shows %hist just fine.

If you start qtconsole with the following in a plain windows cmd console:

C:\Python26\python.exe c:\Python26\Scripts\ipython-qtconsole-script.pyw 
--pylab

Note that I'm using python.exe _not_ pythonw.exe, I get the following in 
the _cmd_ terminal when I try %hist in the qtconsole:

> C:\Python26\python.exe c:\Python26\Scripts\ipython-qtconsole-script.pyw --pylab
>   --IPythonWidget.font_size=13 --no-confirm-exit --autocall=2 
> --no-gui-completion

[IPKernelApp] To connect another client to this kernel, use:
[IPKernelApp] --existing --shell=1158 --iopub=1159 --stdin=1160 --hb=1161
Warning: received unknown payload of type 
u'IPython.zmq.zmqshell.ZMQInteractiveS
hell.auto_rewrite_input'
arange 10

Notice the "Warning: received unknown payload of type 
u'IPython.zmq.zmqshell.ZMQInteractiveS
hell.auto_rewrite_input"

Thus, %hist is reporting history in the cmd terminal, not in the qtconsole.

I hope that helps.

On 7/21/2011 7:35 AM, takluyver wrote:

> A bare %hist will show history from the start of the session, so be sure you've entered a few commands before trying it.
> 
> Does it produce any output after you type %hist? Any error messages? Do you get the next prompt? If you start `ipython qtconsole` (or whatever the command is in Windows) from a command prompt, do you get any error messages there? Does %hist still work in terminal IPython?

On 21 July 2011 16:32, reckoner <
reply@reply.github.com>wrote:

> Thus, %hist is reporting history in the cmd terminal, not in the qtconsole.

The warning is to do with something else, and it's harmless. But you're
right, it does look like the output is appearing at the terminal rather than
being forwarded.

@minrk: The %hist magic currently uses `print(...,
file=IPython.utils.io.stdout)`, and this gets redirected properly on Linux,
but seemingly not on Windows. Should it be printing to another object? Do we
just print to sys.stdout now?

utils.io.stout should be hooked up to sys.stdout (in shell.init_io).  it does a different thing on Windows for pyreadline, but that should only be done with the terminal frontend, rather that always.

-MinRK

On Jul 21, 2011, at 8:52, takluyverreply@reply.github.com wrote:

> On 21 July 2011 16:32, reckoner <
> reply@reply.github.com>wrote:
> 
> > Thus, %hist is reporting history in the cmd terminal, not in the qtconsole.
> 
> The warning is to do with something else, and it's harmless. But you're
> right, it does look like the output is appearing at the terminal rather than
> being forwarded.
> 
> @minrk: The %hist magic currently uses `print(...,
> file=IPython.utils.io.stdout)`, and this gets redirected properly on Linux,
> but seemingly not on Windows. Should it be printing to another object? Do we
> just print to sys.stdout now?
> 
> ## 
> 
> Reply to this email directly or view it on GitHub:
> https://github.com/ipython/ipython/issues/617#issuecomment-1624459

OK, looking at the code, it looks like it's happening an all cases on Windows where pyreadline is in use. I think the ZMQshell should have readline_use default to False (which will also speed up launching it a bit). Pull request coming up.


Resolving patch:
diff --git a/IPython/core/history.py b/IPython/core/history.py
--- a/IPython/core/history.py
+++ b/IPython/core/history.py
@@ -650,6 +650,7 @@ def _format_lineno(session, line):
     if 'g' in opts:         # Glob search
         pattern = "*" + args + "*" if args else "*"
         hist = history_manager.search(pattern, raw=raw, output=get_output)
+        print_nums = True
     elif 'l' in opts:       # Get 'tail'
         try:
             n = int(args)
diff --git a/IPython/zmq/zmqshell.py b/IPython/zmq/zmqshell.py
--- a/IPython/zmq/zmqshell.py
+++ b/IPython/zmq/zmqshell.py
@@ -31,7 +31,7 @@
 from IPython.core.payloadpage import install_payload_page
 from IPython.utils import io
 from IPython.utils.path import get_py_filename
-from IPython.utils.traitlets import Instance, Type, Dict
+from IPython.utils.traitlets import Instance, Type, Dict, CBool
 from IPython.utils.warn import warn
 from IPython.zmq.displayhook import ZMQShellDisplayHook, _encode_png
 from IPython.zmq.session import extract_header
@@ -80,6 +80,11 @@ class ZMQInteractiveShell(InteractiveShell):
     displayhook_class = Type(ZMQShellDisplayHook)
     display_pub_class = Type(ZMQDisplayPublisher)
     
+    # Override the traitlet in the parent class, because there's no point using
+    # readline for the kernel. Can be removed when the readline code is moved
+    # to the terminal frontend.
+    readline_use = CBool(False)
+    
     exiter = Instance(ZMQExitAutocall)
     def _exiter_default(self):
         return ZMQExitAutocall(self)


Test patch: