Discovery: IPython can/does hijack qt/tk app loops (!)

13 views
Skip to first unread message

Edward K. Ream

unread,
Oct 7, 2011, 8:15:54 AM10/7/11
to leo-editor
One of the major mysteries concerning Leo's IPython bridge may have
been resolved.

The reason that the IPython and Qt event loops can coexist is because
IPython "hijacks" (replaces) various event loops!

I'm still studying this. The relevant code (at least in the
maintenance release that supports Leo's IPython bridge) is in
Shell.py.

I'm not sure exactly when the "hijacking" occurs. IPython contains
various threading options, in particular, -q4thread, but I have not
been able to get that to work yet...

At present, the IPython interp runs very slowly when the bridge is in
effect. It may be that specifying the -q4thread option at IPython
startup may help. Or not...

In any event, threading seems to be the topic of the week. IPython is
sophisticated in this regard, so much so that most of what is going on
seems obscure. It's a bit outside my comfort zone, but everything is
in pure Python, so everything can be studied easily.

Edward

Edward K. Ream

unread,
Oct 7, 2011, 8:27:15 AM10/7/11
to leo-editor
On Oct 7, 7:15 am, "Edward K. Ream" <edream...@gmail.com> wrote:
> One of the major mysteries concerning Leo's IPython bridge may have
> been resolved.

Oh my, the interesting, important, even urgent projects keep piling
up :-) In reading the IPython docs I am discovering some nifty new
features, including a built-in Qt shell(!)
http://ipython.org/ipython-doc/dev/interactive/qtconsole.html The
maintenance release probably does not support this.

Anyway, IPython is moving on, and clearly it is time to update Leo's
IPython bridge for IPython's new API's.

As I reread the code in leo/external/ipy_leo.py I have a very strange
feeling. The version history says I wrote the early versions of the
code, but I have zero memory of that. I *think* what happened is that
I wrote a few lines of code while Ville and I were collaborating
initially (this was our first, and most important collaboration) and
then Ville added a lot more code. But I could be wrong.

Anyway, my assumption is that it will be possible to make ipy_leo.py
work for the latest IPython code base. I'd like to do that asap.

Edward

Ville M. Vainio

unread,
Oct 7, 2011, 2:17:04 PM10/7/11
to leo-e...@googlegroups.com

Google for pyos_inputhook

--
You received this message because you are subscribed to the Google Groups "leo-editor" group.
To post to this group, send email to leo-e...@googlegroups.com.
To unsubscribe from this group, send email to leo-editor+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/leo-editor?hl=en.

Edward K. Ream

unread,
Oct 7, 2011, 3:11:35 PM10/7/11
to leo-e...@googlegroups.com
On Fri, Oct 7, 2011 at 1:17 PM, Ville M. Vainio <viva...@gmail.com> wrote:
> Google for pyos_inputhook

Thanks. This certainly is a barrel of worms :-)

I suppose the only essential question is, do you know of any reason
why ipy_leo.py can not be ported to IPython 0.11? I'd like to attempt
this, but of course any help you could give would be appreciated.

Edward

Ville M. Vainio

unread,
Oct 7, 2011, 3:38:44 PM10/7/11
to leo-e...@googlegroups.com

The API (ipapy.py) provided by Ipython has changed since I did
ipy_leo. Back when I last looked into it, the ipython api was in a bad
state of flux as the team was deprecating the old api's before
counterparts were available, for various code clarity reasons. It's
probably stable now, I haven't worked with it for a long while.
IPython also lost a bunch of important (for me functionality) in the
refactoring process, that's why I stuck with the old version and
didn't bother to put work into upgrading ipy_leo (to a version I
wasn't going to use).

I'd recommend you to google "embedding ipython" and work from there. I
will help with any questions I can.

Edward K. Ream

unread,
Oct 7, 2011, 4:21:51 PM10/7/11
to leo-e...@googlegroups.com
On Fri, Oct 7, 2011 at 2:38 PM, Ville M. Vainio <viva...@gmail.com> wrote:

> I'd recommend you to google "embedding ipython" and work from there. I
> will help with any questions I can.

Thanks. These are useful:
http://ipython.org/ipython-doc/dev/interactive/reference.html

http://ipython.org/ipython-doc/dev/api/generated/IPython.lib.inputhook.html#module-IPython.lib.inputhook

Especially:

QQQ
IPython has excellent support for working interactively with Graphical
User Interface (GUI) toolkits, such as wxPython, PyQt4, PyGTK and Tk.
This is implemented using Python’s builtin PyOSInputHook hook. This
implementation is extremely robust compared to our previous
thread-based version. The advantages of this are:

* GUIs can be enabled and disabled dynamically at runtime.
* The active GUI can be switched dynamically at runtime.
* In some cases, multiple GUIs can run simultaneously with no problems.
* There is a developer API in IPython.lib.inputhook for
customizing all of these things.
QQQ

It occurs to me that it might be possible to run (the new) IPython
from blender, and then run Leo from IPython. That is, IPython might
solve some interprocess communications problems that would otherwise
bedevil us.

Edward

Reply all
Reply to author
Forward
0 new messages