[IPython-dev] embedding ipython, namespace question
Darren Dale
dsdale24 at gmail.com
Sat Dec 27 19:22:26 EST 2014
On Sat Dec 27 2014 at 6:58:23 PM Matthias Bussonnier <
bussonniermatthias at gmail.com> wrote:
>
> Le 28 déc. 2014 à 00:24, Darren Dale <dsdale24 at gmail.com> a écrit :
>
> I passed None because
> http://ipython.org/ipython-doc/stable/api/generated/IPython.terminal.embed.html?highlight=embed#IPython.terminal.embed.InteractiveShellEmbed
> states: "If given as None, they are automatically taken from the scope
> where the shell was called, so that program variables become visible." That
> is precisely what I want, but can't figure out how to do it with the Qt
> console.
>
>
> As far as I am concerned, you are not using InteractiveShellEmbed, I don't
> see why you apply docs of one function to
> another.
>
Well, there is not much to be gleaned from the qt in-process documentation
at
http://ipython.org/ipython-doc/stable/api/generated/IPython.qt.inprocess.html#module-IPython.qt.inprocess
. If I call `embed` after I start the kernel and client, I recall getting
an error about attempting multiple instantiations of InteractiveShellEmbed,
so it seemed reasonable to assume that the **kwargs listed in the
in-process docs might map to those documented for InteractiveShellEmbed.
> I don't want to inject variables to an isolated namespace, I want the
> console to share the application's namespace.
>
>
> I did not tell you to pass an isolated namespace, I did tell you to pass
> `globals()` it is not isolated is is a reference to
> current global namespace so it should be shared :
>
My mistake. I guess I misunderstood your comment "You can also do as
raymond said, and inject things into user_ns after getting the reference to
it." That sounds like it injecting variables into an isolated namespace.
I'd try passing globals() instead of None, but I don't know how that should
be done.
http://ipython.org/ipython-doc/stable/api/generated/IPython.qt.inprocess.html#module-IPython.qt.inprocess
only lists **kwargs, and it sounds like the arguments listed for
InteractiveShellEmbed do not necessarily apply to the qt.inprocess
functions/methods.
[...]
> So here, you just need to do it yourself (example a), as the kernel is
> potentially on a different process
>
qt.inprocess is in-process, isn't it?
>
> On Sat Dec 27 2014 at 6:02:54 PM Matthias Bussonnier <
> bussonniermatthias at gmail.com> wrote:
>
>>
>> Le 27 déc. 2014 à 23:43, Darren Dale <dsdale24 at gmail.com> a écrit :
>>
>> Thanks Ray. Unfortunately, I want the ipython console's namespace to
>> reflect that of the application in which it is embedded, not a specific
>> widget. There is an example that appears to do this at
>> https://github.com/ipython/ipython/blob/master/examples/Embedding/embed_function.py
>> , but I'm trying to do the same with the Qt widget. At the top of my main
>> gui module, I do:
>>
>> try:
>> from IPython.qt.console.rich_ipython_widget import RichIPythonWidget
>> from IPython.qt.inprocess import QtInProcessKernelManager
>>
>> # Create an in-process kernel
>> kernel_manager = QtInProcessKernelManager(user_ns=None)
>>
>>
>> Don't you want to just pass `globals()` instead of `None` here?
>> user_ns kwarg here is **the mutable namespace** (i.e. a dict) you want
>> your kernel to work on. If you pass None,
>> it will create a new empty object for you. If you pass `{"a":1}` then
>> your kernel will see a variable `a` with a value of 1 (mutable)
>>
>> So I guess what you want to pass here is either globals(), locals(), or a
>> dict you constructed yourself,
>> from the bit you want available.
>>
>> You can also do as raymond said, and inject things into user_ns after
>> getting the reference to it.
>> --
>> M
>>
>> _______________________________________________
>> IPython-dev mailing list
>> IPython-dev at scipy.org
>> http://mail.scipy.org/mailman/listinfo/ipython-dev
>>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20141228/ffde8e28/attachment.html>
More information about the IPython-dev
mailing list