##// END OF EJS Templates
Merging the config-refactor branch....
Merging the config-refactor branch. This branch did start with the config system refactor, but moved on from there. Here are some highlights. * New config system. * Traitlets * Componenets * Applications * The main ipython program has been refactored to use these new abstractions.

File last commit:

r2276:cdecc6d2
r2278:b8ad0071 merge
Show More
notification_blueprint.txt
123 lines | 5.3 KiB | text/plain | TextLexer
/ docs / source / development / notification_blueprint.txt
Brian Granger
Changes the docs author to the IPython dev team and fixed a few links.
r1676 .. _notification:
Barry Wark
I.k.c.notification blueprint, test, implementation.
r1410
==========================================
IPython.kernel.core.notification blueprint
==========================================
Overview
========
Brian Granger
Updating developer docs.
r1790
The :mod:`IPython.kernel.core.notification` module will provide a simple
implementation of a notification center and support for the observer pattern
within the :mod:`IPython.kernel.core`. The main intended use case is to
provide notification of Interpreter events to an observing frontend during the
execution of a single block of code.
Barry Wark
I.k.c.notification blueprint, test, implementation.
r1410
Functional Requirements
=======================
Brian Granger
Updating developer docs.
r1790
Barry Wark
I.k.c.notification blueprint, test, implementation.
r1410 The notification center must:
Brian Granger
Updating developer docs.
r1790
* Provide synchronous notification of events to all registered observers.
* Provide typed or labeled notification types.
* Allow observers to register callbacks for individual or all notification
types.
* Allow observers to register callbacks for events from individual or all
notifying objects.
* Notification to the observer consists of the notification type, notifying
object and user-supplied extra information [implementation: as keyword
parameters to the registered callback].
* Perform as O(1) in the case of no registered observers.
* Permit out-of-process or cross-network extension.
Brian Granger
Updating the Sphinx docs in preparation for the release....
r1677
Barry Wark
I.k.c.notification blueprint, test, implementation.
r1410 What's not included
Brian Granger
Updating developer docs.
r1790 ===================
Brian Granger
Work on documentation....
r2276 As written, the :mod:`IPython.kernel.core.notification` module does not:
Brian Granger
Updating developer docs.
r1790
* Provide out-of-process or network notifications (these should be handled by
a separate, Twisted aware module in :mod:`IPython.kernel`).
Brian Granger
Work on documentation....
r2276 * Provide zope.interface style interfaces for the notification system (these
Brian Granger
Updating developer docs.
r1790 should also be provided by the :mod:`IPython.kernel` module).
Brian Granger
Updating the Sphinx docs in preparation for the release....
r1677
Barry Wark
I.k.c.notification blueprint, test, implementation.
r1410 Use Cases
=========
Brian Granger
Updating developer docs.
r1790
Brian Granger
Work on documentation....
r2276 The following use cases describe the main intended uses of the notification
module and illustrate the main success scenario for each use case:
Barry Wark
I.k.c.notification blueprint, test, implementation.
r1410
Brian Granger
Work on documentation....
r2276 Scenario 1
----------
Brian Granger
Updating the Sphinx docs in preparation for the release....
r1677
Brian Granger
Work on documentation....
r2276 Dwight Schroot is writing a frontend for the IPython project. His frontend is
stuck in the stone age and must communicate synchronously with an
:mod:`IPython.kernel.core.Interpreter` instance. Because code is executed in blocks
by the Interpreter, Dwight's UI freezes every time he executes a long block of
code. To keep track of the progress of his long running block, Dwight adds the
following code to his frontend's set-up code::
from IPython.kernel.core.notification import NotificationCenter
center = NotificationCenter.sharedNotificationCenter
center.registerObserver(self, type=IPython.kernel.core.Interpreter.STDOUT_NOTIFICATION_TYPE, notifying_object=self.interpreter, callback=self.stdout_notification)
Brian Granger
Updating the Sphinx docs in preparation for the release....
r1677
Brian Granger
Work on documentation....
r2276 and elsewhere in his front end::
def stdout_notification(self, type, notifying_object, out_string=None):
self.writeStdOut(out_string)
Brian Granger
Updating the Sphinx docs in preparation for the release....
r1677
Brian Granger
Updating developer docs.
r1790 If everything works, the Interpreter will (according to its published API)
fire a notification via the
:data:`IPython.kernel.core.notification.sharedCenter` of type
:const:`STD_OUT_NOTIFICATION_TYPE` before writing anything to stdout [it's up
to the Intereter implementation to figure out when to do this]. The
notificaiton center will then call the registered callbacks for that event
type (in this case, Dwight's frontend's stdout_notification method). Again,
according to its API, the Interpreter provides an additional keyword argument
when firing the notificaiton of out_string, a copy of the string it will write
to stdout.
Brian Granger
Updating the Sphinx docs in preparation for the release....
r1677
Brian Granger
Updating developer docs.
r1790 Like magic, Dwight's frontend is able to provide output, even during
long-running calculations. Now if Jim could just convince Dwight to use
Twisted...
Brian Granger
Updating the Sphinx docs in preparation for the release....
r1677
Brian Granger
Work on documentation....
r2276 Scenario 2
----------
Boss Hog is writing a frontend for the IPython project. Because Boss Hog is
Brian Granger
Cleanup of docs....
r2275 stuck in the stone age, his frontend will be written in a new Fortran-like
dialect of python and will run only from the command line. Because he doesn't
need any fancy notification system and is used to worrying about every cycle
on his rat-wheel powered mini, Boss Hog is adamant that the new notification
system not produce any performance penalty. As they say in Hazard county,
there's no such thing as a free lunch. If he wanted zero overhead, he should
have kept using IPython 0.8. Instead, those tricky Duke boys slide in a
suped-up bridge-out jumpin' awkwardly confederate-lovin' notification module
that imparts only a constant (and small) performance penalty when the
Interpreter (or any other object) fires an event for which there are no
registered observers. Of course, the same notificaiton-enabled Interpreter can
then be used in frontends that require notifications, thus saving the IPython
project from a nasty civil war.
Brian Granger
Work on documentation....
r2276
Scenario 3
----------
Barry is wrting a frontend for the IPython project. Because Barry's front end
is the *new hotness*, it uses an asynchronous event model to communicate with
a Twisted :mod:`IPython.kernel.engineservice` that communicates with the
IPython :class:`IPython.kernel.core.interpreter.Interpreter`. Using the
Brian Granger
Cleanup of docs....
r2275 :mod:`IPython.kernel.notification` module, an asynchronous wrapper on the
:mod:`IPython.kernel.core.notification` module, Barry's frontend can register
for notifications from the interpreter that are delivered asynchronously. Even
if Barry's frontend is running on a separate process or even host from the
Interpreter, the notifications are delivered, as if by dark and twisted magic.
Brian Granger
Work on documentation....
r2276 Just like Dwight's frontend, Barry's frontend can now receive notifications of
Brian Granger
Cleanup of docs....
r2275 e.g. writing to stdout/stderr, opening/closing an external file, an exception
in the executing code, etc.