[IPython-dev] IPython authentication
Tue Feb 5 00:09:13 CST 2013
On Mon, Feb 4, 2013 at 9:44 PM, Wojciech Daniło
> Benjamin thank you very much for yours answer! I'm very happy that all the
> things are implemented - I'm starting to test these things out :)
> If I could I owuld ask you additional 2, a little more precious questions:
> 1) Lets concider we have kernel K and clients A and B. If client A
> executes something on K, I would like K to send notification about it to B
> (broadcast to clients) - I think youre talking about something like that
> (or am I wrong?).
Yes, this is the `pyin` message. It is sent to all clients on the iopub
channel when an execute_request begins (prior to evaluating that request).
> 2) Additional when A or B executes a command on K it will run some
> functions from my batch python module. Is it possible that these functions
> will broadcast some customized messages to client with the functionality
> provided by Kernel?
Yes, if you modify the kernel. You might be able to get away with just
registering a `post_execute_hook` in IPython.
> So basically is it possible to send to Kernel and from Kernel to clients
> customized messages with custom fields etc (extend the handling mechanizm)
> or should I implement this next to the IPython communication mechanism (I
> do not want to implement that next to it, because that is a little bit ugly
> ;) )
I would recommend trying to use the existing functionality as best you can.
In general, you would use:
publisher = get_ipython().display_pub
That should let you publish fairly arbitrary data to the clients.
> Thank you once again!
> 2013/2/5 MinRK <firstname.lastname@example.org>
>> On Mon, Feb 4, 2013 at 9:08 PM, Wojciech Daniło <
>> email@example.com> wrote:
>>> I'm new to IPython, but this project seems like a very good
>>> "boilerplate" for my custom project. I've read a lot of docs and looked at
>>> the source code and I want to ask you if something I want to do with
>>> IPython is possible.
>>> I want to run a IPython Kernel on a machine. It will execute my batch
>>> program. I want users to be able to connect to this kernel (locally or over
>>> network) and execute Python code - everything so far is provided by IPython
>>> i think.
>>> The problem is, I want to know WHICH user executed the code, because I
>>> want to make something like collaboration model - If one user executes a
>>> code - lets say "draw line", I want this line t show in the second user GUI
>>> with a tooltip, which user executed it.
>>> Is it somehow possible? Could you give me any hints how to do it?
>> Messages have a 'session' key, which is unique, and a username in the
>> header (generally the unix username). These are attributes of the Session
>> object, so at the very least every frontend (aka client aka user session)
>> has a unique ID. The header of each request is attached as the
>> 'parent_header' of replies and side effects of the request. Among these
>> side effects (of execute_requests) are:
>> pyin: the Python code just run
>> display_data: display side effects
>> stream: stdout/stderr
>> And these come to all frontends on the iopub channel.
>> So let's say you have two frontends attached to the Kernel. When a
>> 'pyin' message comes in on the iopub channel, and you check it, you can
>> trigger an event based on the content and parent_header, such as "client
>> [FOO] just ran this code: etc.".
>> If you want to draw the display *results* of the execution, they will be
>> `display_data` messages on the same channel, and you can associate them
>> with their source in the same way.
>> That should be all you need, I think.
>> IPython-dev mailing list
> IPython-dev mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-dev