##// END OF EJS Templates
Merge Omar's Zmq proposal, formatting cleanups.
Fernando Perez -
r2590:3c4bd4c6 merge
parent child Browse files
Show More
@@ -0,0 +1,116 b''
1 .. _ipythonzmq:
2
3 =====================================================
4 Porting IPython to a two process model using zeromq
5 =====================================================
6
7 Abstract
8 --------
9
10 IPython's execution in a command-line environment will be ported to a two
11 process model using the zeromq library for inter-process communication. this
12 will:
13
14 - prevent an interpreter crash from destroying the user session,
15 - allow multiple clients to interact simultaneously with a single interpreter
16 - allow IPython to reuse code for local execution and distributed computing (dc)
17 - give us a path for python3 support, since zeromq supports python3 while
18 twisted (what we use today for dc) does not.
19
20
21 Project description
22 -------------------
23
24 Currently IPython provides a command-line client that executes all code in a
25 single process, and a set of tools for distributed and parallel computing that
26 execute code in multiple processes (possibly but not necessarily on different
27 hosts), using the twisted asynchronous framework for communication between
28 nodes. for a number of reasons, it is desirable to unify the architecture of
29 the local execution with that of distributed computing, since ultimately many
30 of the underlying abstractions are similar and should be reused. in
31 particular, we would like to:
32
33 - have even for a single user a 2-process model, so that the environment where
34 code is being input runs in a different process from that which executes the
35 code. this would prevent a crash of the python interpreter executing code
36 (because of a segmentation fault in a compiled extension or an improper
37 access to a c library via ctypes, for example) from destroying the user
38 session.
39
40 - have the same kernel used for executing code locally be available over the
41 network for distributed computing. currently the twisted-using IPython
42 engines for distributed computing do not share any code with the command-line
43 client, which means that many of the additional features of IPython (tab
44 completion, object introspection, magic functions, etc) are not available
45 while using the distributed computing system. once the regular command-line
46 environment is ported to allowing such a 2-process model, this newly
47 decoupled kernel could form the core of a distributed computing IPython
48 engine and all capabilities would be available throughout the system.
49
50 - have a route to python3 support. twisted is a large and complex library that
51 does currently not support python3, and as indicated by the twisted
52 developers it may take a while before it is ported
53 (http://stackoverflow.com/questions/172306/how-are-you-planning-on-handling-the-migration-to-python-3).
54 for IPython, this means that while we could port the command-line
55 environment, a large swath of IPython would be left 2.x-only, a highly
56 undesirable situation. for this reason, the search for an alternative to
57 twisted has been active for a while, and recently we've identified the zeromq
58 (http://www.zeromq.org, zmq for short) library as a viable candidate. zmq is
59 a fast, simple messaging library written in c++, for which one of the IPython
60 developers has written python bindings using cython
61 (http://www.zeromq.org/bindings:python). since cython already knows how to
62 generate python3-compliant bindings with a simple command-line switch, zmq
63 can be used with python3 when needed.
64
65 As part of the zmq python bindings, the IPython developers have already
66 developed a simple prototype of such a two-process kernel/frontend system
67 (details below). I propose to start from this example and port today's IPython
68 code to operate in a similar manner. IPython's command-line program (the main
69 'ipython' script) executes both user interaction and the user's code in the
70 same process. This project will thus require breaking up IPython into the parts
71 that correspond to the kernel and the parts that are meant to interact with the
72 user, and making these two components communicate over the network using zmq
73 instead of accessing local attributes and methods of a single global object.
74
75 Once this port is complete, the resulting tools will be the foundation (though
76 as part of this proposal i do not expect to undertake either of these tasks) to
77 allow the distributed computing parts of IPython to use the same code as the
78 command-line client, and for the whole system to be ported to python3. so
79 while i do not intend to tackle here the removal of twisted and the unification
80 of the local and distributed parts of IPython, my proposal is a necessary step
81 before those are possible.
82
83 Project details
84 ---------------
85
86 As part of the zeromq bindings, the IPython developers have already developed a
87 simple prototype example that provides a python execution kernel (with none of
88 IPython's code or features, just plain code execution) that listens on zmq
89 sockets, and a frontend based on the interactiveconsole class of the code.py
90 module from the python standard library. this example is capable of executing
91 code, propagating errors, performing tab-completion over the network and having
92 multiple frontends connect and disconnect simultaneously to a single kernel,
93 with all inputs and outputs being made available to all connected clients
94 (thanks to zqm's pub sockets that provide multicasting capabilities for the
95 kernel and to which the frontends subscribe via a sub socket).
96
97 We have all example code in:
98
99 * http://github.com/ellisonbg/pyzmq/blob/completer/examples/kernel/kernel.py
100 * http://github.com/ellisonbg/pyzmq/blob/completer/examples/kernel/completer.py
101 * http://github.com/fperez/pyzmq/blob/completer/examples/kernel/frontend.py
102
103 all of this code already works, and can be seen in this example directory from
104 the zmq python bindings:
105
106 * http://github.com/ellisonbg/pyzmq/blob/completer/examples/kernel
107
108 Based on this work, i expect to write a stable system for IPython kernel with
109 IPython standards, error control,crash recovery system and general
110 configuration options, also standardize defaults ports or auth system for
111 remote connection etc.
112
113 The crash recovery system, is a IPython kernel module for when it fails
114 unexpectedly, you can retrieve the information from the section, this will be
115 based on a log and a lock file to indicate when the kernel was not closed in a
116 proper way.
@@ -18,3 +18,4 b" IPython developer's guide"
18 notification_blueprint.txt
18 notification_blueprint.txt
19 ipgraph.txt
19 ipgraph.txt
20 ipython_qt.txt
20 ipython_qt.txt
21 ipythonzmq.txt
@@ -5,32 +5,59 b' IPython Qt interface'
5 ====================
5 ====================
6
6
7 Abstract
7 Abstract
8 ------------
8 --------
9
9
10 This is about the implementation of a Qt-based Graphical User Interface (GUI) to execute Python code with an interpreter that runs in a separate process and the two systems (GUI frontend and interpreter kernel) communicating via the ZeroMQ Messaging library. The bulk of the implementation will be done without dependencies on IPython (only on Zmq). Once the key features are ready, IPython-specific features can be added using the IPython codebase.
10 This is about the implementation of a Qt-based Graphical User Interface (GUI)
11 to execute Python code with an interpreter that runs in a separate process and
12 the two systems (GUI frontend and interpreter kernel) communicating via the
13 ZeroMQ Messaging library. The bulk of the implementation will be done without
14 dependencies on IPython (only on Zmq). Once the key features are ready,
15 IPython-specific features can be added using the IPython codebase.
11
16
12
17
13 Project details
18 Project details
14 -------------------
19 ---------------
15
20
16 For a long time there has been demand for a graphical user interface for IPython, and the project already ships Wx-based prototypes thereof. But these run all code in a single process, making them extremely brittle, as a crash of the Python interpreter kills the entire user session. Here I propose to build a Qt-based GUI that will communicate with a separate process for the code execution, so that if the interpreter kernel dies, the frontend can continue to function after restarting a new kernel (and offering the user the option to re-execute all inputs, which the frontend can know).
21 For a long time there has been demand for a graphical user interface for
22 IPython, and the project already ships Wx-based prototypes thereof. But these
23 run all code in a single process, making them extremely brittle, as a crash of
24 the Python interpreter kills the entire user session. Here I propose to build
25 a Qt-based GUI that will communicate with a separate process for the code
26 execution, so that if the interpreter kernel dies, the frontend can continue to
27 function after restarting a new kernel (and offering the user the option to
28 re-execute all inputs, which the frontend can know).
17
29
18 This GUI will allow for the easy editing of multi-line input and the convenient re-editing of previous blocks of input, which can be displayed in a 2-d workspace instead of a line-driven one like today's IPython. This makes it much easier to incrementally build and tune a code, by combining the rapid feedback cycle of IPython with the ability to edit multiline code with good graphical support.
30 This GUI will allow for the easy editing of multi-line input and the convenient
31 re-editing of previous blocks of input, which can be displayed in a 2-d
32 workspace instead of a line-driven one like today's IPython. This makes it much
33 easier to incrementally build and tune a code, by combining the rapid feedback
34 cycle of IPython with the ability to edit multiline code with good graphical
35 support.
19
36
20
37
21 2-process model pyzmq base
38 2-process model pyzmq base
22 ++++++++++++++++++++++++++
39 ~~~~~~~~~~~~~~~~~~~~~~~~~~
23 Since the necessity of a user to keep his data safe, the design is based in a 2-process model that will be achieved with a simple client/server system with `pyzmq <http://www.zeromq.org/bindings:python>`_, so the GUI session do not crash if the the kernel process does. This will be achieved using this test `code <http://github.com/fperez/pyzmq/blob/completer/examples/kernel/kernel.py>`_ and customizing it to the necessities of the GUI such as queue management with discrimination for different frontends connected to the same kernel and tab completion. A piece of drafted code for the kernel (server) should look like this::
40
41 Since the necessity of a user to keep his data safe, the design is based in a
42 2-process model that will be achieved with a simple client/server system with
43 `pyzmq <http://www.zeromq.org/bindings:python>`_, so the GUI session do not
44 crash if the the kernel process does. This will be achieved using this test
45 `code
46 <http://github.com/fperez/pyzmq/blob/completer/examples/kernel/kernel.py>`_ and
47 customizing it to the necessities of the GUI such as queue management with
48 discrimination for different frontends connected to the same kernel and tab
49 completion. A piece of drafted code for the kernel (server) should look like
50 this::
24
51
25 def main():
52 def main():
26 c = zmq.Context(1, 1)
53 c = zmq.Context(1, 1)
27 rep_conn = connection % port_base
54 rep_conn = connection % port_base
28 pub_conn = connection % (port_base+1)
55 pub_conn = connection % (port_base+1)
29 print >>sys.__stdout__, "Starting the kernel..."
56 print >>sys.__stdout__, "Starting the kernel..."
30 print >>sys.__stdout__, "On:",rep_conn, pub_conn
57 print >>sys.__stdout__, "On:",rep_conn, pub_conn
31 session = Session(username=u'kernel')
58 session = Session(username=u'kernel')
32 reply_socket = c.socket(zmq.XREP)
59 reply_socket = c.socket(zmq.XREP)
33 reply_socket.bind(rep_conn)
60 reply_socket.bind(rep_conn)
34 pub_socket = c.socket(zmq.PUB)
61 pub_socket = c.socket(zmq.PUB)
35 pub_socket.bind(pub_conn)
62 pub_socket.bind(pub_conn)
36 stdout = OutStream(session, pub_socket, u'stdout')
63 stdout = OutStream(session, pub_socket, u'stdout')
@@ -38,24 +65,50 b' Since the necessity of a user to keep his data safe, the design is based in a 2-'
38 sys.stdout = stdout
65 sys.stdout = stdout
39 sys.stderr = stderr
66 sys.stderr = stderr
40 display_hook = DisplayHook(session, pub_socket)
67 display_hook = DisplayHook(session, pub_socket)
41 sys.displayhook = display_hook
68 sys.displayhook = display_hook
42 kernel = Kernel(session, reply_socket, pub_socket)
69 kernel = Kernel(session, reply_socket, pub_socket)
43
70
44 This kernel will use two queues (output and input), the input queue will have the id of the process(frontend) making the request, type(execute, complete, help, etc) and id of the request itself and the string of code to be executed, the output queue will have basically the same information just that the string is the to be displayed. This model is because the kernel needs to maintain control of timeouts when multiple requests are sent and keep them indexed.
71 This kernel will use two queues (output and input), the input queue will have
72 the id of the process(frontend) making the request, type(execute, complete,
73 help, etc) and id of the request itself and the string of code to be executed,
74 the output queue will have basically the same information just that the string
75 is the to be displayed. This model is because the kernel needs to maintain
76 control of timeouts when multiple requests are sent and keep them indexed.
45
77
46 Qt based GUI
78 Qt based GUI
47 ++++++++++++
79 ~~~~~~~~~~~~
48 Design of the interface is going to be based in cells of code executed on the previous defined kernel. It will also have GUI facilities such toolboxes, tooltips to autocomplete code and function summary, highlighting and autoindentation.
80
49 It will have the cell kind of multiline edition mode so each block of code can be edited and executed independently, this can be achieved queuing QTextEdit objects (the cell) giving them format so we can discriminate outputs from inputs.
81 Design of the interface is going to be based in cells of code executed on the
50 One of the main characteristics will be the debug support that will show the requested outputs as the debugger (that will be on a popup widget) "walks" through the code, this design is to be reviewed with the mentor.
82 previous defined kernel. It will also have GUI facilities such toolboxes,
51 `This <http://gfif.udea.edu.co/IPythonQt_snapshot.png>`_ is a tentative view of the main window.
83 tooltips to autocomplete code and function summary, highlighting and
52
84 autoindentation. It will have the cell kind of multiline edition mode so each
53 The GUI will check continuously the output queue from the kernel for new information to handle. This information have to be handled with care since any output will come at anytime and possibly in a different order than requested or maybe not appear at all, this could be possible due to a variety of reasons(for example tab completion request while the kernel is busy processing another frontend's request). This is, if the kernel is busy it won't be possible to fulfill the request for a while so the GUI will be prepared to abandon waiting for the reply if the user moves on or a certain timeout expires.
85 block of code can be edited and executed independently, this can be achieved
86 queuing QTextEdit objects (the cell) giving them format so we can discriminate
87 outputs from inputs. One of the main characteristics will be the debug support
88 that will show the requested outputs as the debugger (that will be on a popup
89 widget) "walks" through the code, this design is to be reviewed with the
90 mentor. `This <http://gfif.udea.edu.co/IPythonQt_snapshot.png>`_ is a
91 tentative view of the main window.
92
93 The GUI will check continuously the output queue from the kernel for new
94 information to handle. This information have to be handled with care since any
95 output will come at anytime and possibly in a different order than requested or
96 maybe not appear at all, this could be possible due to a variety of reasons(for
97 example tab completion request while the kernel is busy processing another
98 frontend's request). This is, if the kernel is busy it won't be possible to
99 fulfill the request for a while so the GUI will be prepared to abandon waiting
100 for the reply if the user moves on or a certain timeout expires.
54
101
55
102
56 POSSIBLE FUTURE DIRECTIONS
103 POSSIBLE FUTURE DIRECTIONS
57 ---------------------------
104 ---------------------------
58
105
59 The near future will bring the feature of saving and loading sessions, also importing and exporting to different formats like rst, html, pdf and python/ipython code, a discussion about this is taking place in the ipython-dev mailing list. Also the interaction with a remote kernel and distributed computation which is an IPython's project already in development.
106 The near future will bring the feature of saving and loading sessions, also
107 importing and exporting to different formats like rst, html, pdf and
108 python/ipython code, a discussion about this is taking place in the ipython-dev
109 mailing list. Also the interaction with a remote kernel and distributed
110 computation which is an IPython's project already in development.
60
111
61 The idea of a mathematica-like help widget (i.e. there will be parts of it that will execute as a native session of IPythonQt) is still to be discussed in the development mailing list but it's definitively a great idea. No newline at end of file
112 The idea of a mathematica-like help widget (i.e. there will be parts of it that
113 will execute as a native session of IPythonQt) is still to be discussed in the
114 development mailing list but it's definitively a great idea.
General Comments 0
You need to be logged in to leave comments. Login now