##// END OF EJS Templates
Continuing work on ipcontroller.
Brian Granger -
Show More
@@ -0,0 +1,60 b''
1 from IPython.config.loader import Config
2
3 c = get_config()
4
5 #-----------------------------------------------------------------------------
6 # Global configuration
7 #-----------------------------------------------------------------------------
8
9 c.Global.logfile = ''
10 c.Global.import_statement = ''
11 c.Global.reuse_furls = False
12
13
14 #-----------------------------------------------------------------------------
15 # Configure the client services
16 #-----------------------------------------------------------------------------
17
18 c.FCClientServiceFactory.ip = ''
19 c.FCClientServiceFactory.port = 0
20 c.FCClientServiceFactory.location = ''
21 c.FCClientServiceFactory.secure = True
22 c.FCClientServiceFactory.cert_file = 'ipcontroller-client.pem'
23
24 c.FCClientServiceFactory.Interfaces.Task.interface_chain = [
25 'IPython.kernel.task.ITaskController',
26 'IPython.kernel.taskfc.IFCTaskController'
27 ]
28 c.FCClientServiceFactory.Interfaces.Task.furl_file = 'ipcontroller-tc.furl'
29
30 c.FCClientServiceFactory.Interfaces.MultiEngine.interface_chain = [
31 'IPython.kernel.multiengine.IMultiEngine',
32 'IPython.kernel.multienginefc.IFCSynchronousMultiEngine'
33 ]
34 c.FCClientServiceFactory.Interfaces.MultiEngine.furl_file = 'ipcontroller-mec.furl'
35
36
37 #-----------------------------------------------------------------------------
38 # Configure the engine services
39 #-----------------------------------------------------------------------------
40
41 c.FCEngineServiceFactory.ip = ''
42 c.FCEngineServiceFactory.port = 0
43 c.FCEngineServiceFactory.location = ''
44 c.FCEngineServiceFactory.secure = True
45 c.FCEngineServiceFactory.cert_file = 'ipcontroller-engine.pem'
46
47 engine_config = Config()
48 engine_config.furl_file =
49 c.Global.engine_furl_file = 'ipcontroller-engine.furl'
50 c.Global.engine_fc_interface = 'IPython.kernel.enginefc.IFCControllerBase'
51
52
53
54
55
56 CLIENT_INTERFACES = dict(
57 TASK = dict(FURL_FILE = 'ipcontroller-tc.furl'),
58 MULTIENGINE = dict(FURLFILE='ipcontroller-mec.furl')
59 )
60
@@ -0,0 +1,19 b''
1 c = get_config()
2
3 c.MPI.default = 'mpi4py'
4
5 c.MPI.mpi4py = """from mpi4py import MPI as mpi
6 mpi.size = mpi.COMM_WORLD.Get_size()
7 mpi.rank = mpi.COMM_WORLD.Get_rank()
8 """
9
10 c.MPI.pytrilinos = """from PyTrilinos import Epetra
11 class SimpleStruct:
12 pass
13 mpi = SimpleStruct()
14 mpi.rank = 0
15 mpi.size = 0
16 """
17
18 c.Global.logfile = ''
19 c.Global.furl_file = 'ipcontroller-engine.furl'
@@ -0,0 +1,75 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 """
4 A class for creating a Twisted service that is configured using IPython's
5 configuration system.
6 """
7
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2009 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
18
19 import zope.interface as zi
20
21 from IPython.core.component import Component
22
23 #-----------------------------------------------------------------------------
24 # Code
25 #-----------------------------------------------------------------------------
26
27
28 class IConfiguredObjectFactory(zi.Interface):
29 """I am a component that creates a configured object.
30
31 This class is useful if you want to configure a class that is not a
32 subclass of :class:`IPython.core.component.Component`.
33 """
34
35 def __init__(config):
36 """Get ready to configure the object using config."""
37
38 def create():
39 """Return an instance of the configured object."""
40
41
42 class ConfiguredObjectFactory(Component):
43
44 zi.implements(IConfiguredObjectFactory)
45
46 def __init__(self, config):
47 super(ConfiguredObjectFactory, self).__init__(None, config=config)
48
49 def create(self):
50 raise NotImplementedError('create must be implemented in a subclass')
51
52
53 class IAdaptedConfiguredObjectFactory(zi.Interface):
54 """I am a component that adapts and configures an object.
55
56 This class is useful if you have the adapt a instance and configure it.
57 """
58
59 def __init__(config, adaptee=None):
60 """Get ready to adapt adaptee and then configure it using config."""
61
62 def create():
63 """Return an instance of the adapted and configured object."""
64
65
66 class AdaptedConfiguredObjectFactory(Component):
67
68 # zi.implements(IAdaptedConfiguredObjectFactory)
69
70 def __init__(self, config, adaptee):
71 super(AdaptedConfiguredObjectFactory, self).__init__(None, config=config)
72 self.adaptee = adaptee
73
74 def create(self):
75 raise NotImplementedError('create must be implemented in a subclass') No newline at end of file
@@ -0,0 +1,266 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 """
4 The IPython controller application
5 """
6
7 #-----------------------------------------------------------------------------
8 # Copyright (C) 2008-2009 The IPython Development Team
9 #
10 # Distributed under the terms of the BSD License. The full license is in
11 # the file COPYING, distributed as part of this software.
12 #-----------------------------------------------------------------------------
13
14 #-----------------------------------------------------------------------------
15 # Imports
16 #-----------------------------------------------------------------------------
17
18 import copy
19 import os
20 import sys
21
22 from twisted.application import service
23 from twisted.internet import reactor, defer
24 from twisted.python import log
25
26 from IPython.config.loader import Config, NoConfigDefault
27
28 from IPython.core.application import Application, IPythonArgParseConfigLoader
29 from IPython.core import release
30
31 from IPython.utils.traitlets import Int, Str, Bool, Instance
32 from IPython.utils.importstring import import_item
33
34 from IPython.kernel import controllerservice
35 from IPython.kernel.configobjfactory import (
36 ConfiguredObjectFactory,
37 AdaptedConfiguredObjectFactory
38 )
39
40 from IPython.kernel.fcutil import FCServiceFactory
41
42 #-----------------------------------------------------------------------------
43 # Components for creating services
44 #-----------------------------------------------------------------------------
45
46
47 # The default client interfaces for FCClientServiceFactory.Interfaces
48 default_client_interfaces = Config()
49 default_client_interfaces.Task.interface_chain = [
50 'IPython.kernel.task.ITaskController',
51 'IPython.kernel.taskfc.IFCTaskController'
52 ]
53 default_client_interfaces.Task.furl_file = 'ipcontroller-tc.furl'
54 default_client_interfaces.MultiEngine.interface_chain = [
55 'IPython.kernel.multiengine.IMultiEngine',
56 'IPython.kernel.multienginefc.IFCSynchronousMultiEngine'
57 ]
58 default_client_interfaces.MultiEngine.furl_file = 'ipcontroller-mec.furl'
59
60 # Make this a dict we can pass to Config.__init__ for the default
61 default_client_interfaces = dict(copy.deepcopy(default_client_interfaces.items()))
62
63
64
65 # The default engine interfaces for FCEngineServiceFactory.Interfaces
66 default_engine_interfaces = Config()
67 default_engine_interfaces.Default.interface_chain = [
68 'IPython.kernel.enginefc.IFCControllerBase'
69 ]
70 default_engine_interfaces.Default.furl_file = 'ipcontroller-engine.furl'
71
72 # Make this a dict we can pass to Config.__init__ for the default
73 default_engine_interfaces = dict(copy.deepcopy(default_engine_interfaces.items()))
74
75
76
77 class FCClientServiceFactory(FCServiceFactory):
78 """A Foolscap implementation of the client services."""
79
80 cert_file = Str('ipcontroller-client.pem', config=True)
81 Interfaces = Instance(klass=Config, kw=default_client_interfaces,
82 allow_none=False, config=True)
83
84
85 class FCEngineServiceFactory(FCServiceFactory):
86 """A Foolscap implementation of the engine services."""
87
88 cert_file = Str('ipcontroller-engine.pem', config=True)
89 interfaces = Instance(klass=dict, kw=default_engine_interfaces,
90 allow_none=False, config=True)
91
92
93 #-----------------------------------------------------------------------------
94 # The main application
95 #-----------------------------------------------------------------------------
96
97
98 cl_args = (
99 # Client config
100 (('--client-ip',), dict(
101 type=str, dest='FCClientServiceFactory.ip', default=NoConfigDefault,
102 help='The IP address or hostname the controller will listen on for client connections.',
103 metavar='FCClientServiceFactory.ip')
104 ),
105 (('--client-port',), dict(
106 type=int, dest='FCClientServiceFactory.port', default=NoConfigDefault,
107 help='The port the controller will listen on for client connections.',
108 metavar='FCClientServiceFactory.port')
109 ),
110 (('--client-location',), dict(
111 type=str, dest='FCClientServiceFactory.location', default=NoConfigDefault,
112 help='The hostname or ip that clients should connect to.',
113 metavar='FCClientServiceFactory.location')
114 ),
115 (('-x',), dict(
116 action='store_false', dest='FCClientServiceFactory.secure', default=NoConfigDefault,
117 help='Turn off all client security.')
118 ),
119 (('--client-cert-file',), dict(
120 type=str, dest='FCClientServiceFactory.cert_file', default=NoConfigDefault,
121 help='File to store the client SSL certificate in.',
122 metavar='FCClientServiceFactory.cert_file')
123 ),
124 (('--task-furl-file',), dict(
125 type=str, dest='FCClientServiceFactory.Interfaces.Task.furl_file', default=NoConfigDefault,
126 help='File to store the FURL in for task clients to connect with.',
127 metavar='FCClientServiceFactory.Interfaces.Task.furl_file')
128 ),
129 (('--multiengine-furl-file',), dict(
130 type=str, dest='FCClientServiceFactory.Interfaces.MultiEngine.furl_file', default=NoConfigDefault,
131 help='File to store the FURL in for multiengine clients to connect with.',
132 metavar='FCClientServiceFactory.Interfaces.MultiEngine.furl_file')
133 ),
134 # Engine config
135 (('--engine-ip',), dict(
136 type=str, dest='FCEngineServiceFactory.ip', default=NoConfigDefault,
137 help='The IP address or hostname the controller will listen on for engine connections.',
138 metavar='FCEngineServiceFactory.ip')
139 ),
140 (('--engine-port',), dict(
141 type=int, dest='FCEngineServiceFactory.port', default=NoConfigDefault,
142 help='The port the controller will listen on for engine connections.',
143 metavar='FCEngineServiceFactory.port')
144 ),
145 (('--engine-location',), dict(
146 type=str, dest='FCEngineServiceFactory.location', default=NoConfigDefault,
147 help='The hostname or ip that engines should connect to.',
148 metavar='FCEngineServiceFactory.location')
149 ),
150 (('-y',), dict(
151 action='store_false', dest='FCEngineServiceFactory.secure', default=NoConfigDefault,
152 help='Turn off all engine security.')
153 ),
154 (('--engine-cert-file',), dict(
155 type=str, dest='FCEngineServiceFactory.cert_file', default=NoConfigDefault,
156 help='File to store the client SSL certificate in.',
157 metavar='FCEngineServiceFactory.cert_file')
158 ),
159 (('--engine-furl-file',), dict(
160 type=str, dest='FCEngineServiceFactory.Interfaces.Default.furl_file', default=NoConfigDefault,
161 help='File to store the FURL in for engines to connect with.',
162 metavar='FCEngineServiceFactory.Interfaces.Default.furl_file')
163 ),
164 # Global config
165 (('-l','--logfile'), dict(
166 type=str, dest='Global.logfile', default=NoConfigDefault,
167 help='Log file name (default is stdout)',
168 metavar='Global.logfile')
169 ),
170 (('-r',), dict(
171 action='store_true', dest='Global.reuse_furls', default=NoConfigDefault,
172 help='Try to reuse all FURL files.')
173 )
174 )
175
176
177 class IPControllerAppCLConfigLoader(IPythonArgParseConfigLoader):
178
179 arguments = cl_args
180
181
182 _default_config_file_name = 'ipcontroller_config.py'
183
184 class IPControllerApp(Application):
185
186 name = 'ipcontroller'
187 config_file_name = _default_config_file_name
188
189 def create_default_config(self):
190 super(IPControllerApp, self).create_default_config()
191 self.default_config.Global.logfile = ''
192 self.default_config.Global.reuse_furls = False
193 self.default_config.Global.import_statements = []
194
195 def create_command_line_config(self):
196 """Create and return a command line config loader."""
197
198 return IPControllerAppCLConfigLoader(
199 description="Start an IPython controller",
200 version=release.version)
201
202 def construct(self):
203 # I am a little hesitant to put these into InteractiveShell itself.
204 # But that might be the place for them
205 sys.path.insert(0, '')
206
207 self.start_logging()
208 self.import_statements()
209 self.reuse_furls()
210
211 # Create the service hierarchy
212 self.main_service = service.MultiService()
213 # The controller service
214 controller_service = controllerservice.ControllerService()
215 controller_service.setServiceParent(self.main_service)
216 # The client tub and all its refereceables
217 csfactory = FCClientServiceFactory(self.master_config, controller_service)
218 client_service = csfactory.create()
219 client_service.setServiceParent(self.main_service)
220 # The engine tub
221 esfactory = FCEngineServiceFactory(self.master_config, controller_service)
222 engine_service = esfactory.create()
223 engine_service.setServiceParent(self.main_service)
224
225 def start_logging(self):
226 logfile = self.master_config.Global.logfile
227 if logfile:
228 logfile = logfile + str(os.getpid()) + '.log'
229 try:
230 openLogFile = open(logfile, 'w')
231 except:
232 openLogFile = sys.stdout
233 else:
234 openLogFile = sys.stdout
235 log.startLogging(openLogFile)
236
237 def import_statements(self):
238 statements = self.master_config.Global.import_statements
239 for s in statements:
240 try:
241 exec s in globals(), locals()
242 except:
243 log.msg("Error running import statement: %s" % s)
244
245 def reuse_furls(self):
246 # This logic might need to be moved into the components
247 # Delete old furl files unless the reuse_furls is set
248 reuse = self.master_config.Global.reuse_furls
249 # if not reuse:
250 # paths = (
251 # self.master_config.FCEngineServiceFactory.Interfaces.Default.furl_file,
252 # self.master_config.FCClientServiceFactory.Interfaces.Task.furl_file,
253 # self.master_config.FCClientServiceFactory.Interfaces.MultiEngine.furl_file
254 # )
255 # for p in paths:
256 # if os.path.isfile(p):
257 # os.remove(p)
258
259 def start_app(self):
260 # Start the controller service and set things running
261 self.main_service.startService()
262 reactor.run()
263
264 if __name__ == '__main__':
265 app = IPControllerApp()
266 app.start()
@@ -0,0 +1,17 b''
1 # This shows how to use the new top-level embed function. It is a simpler
2 # API that manages the creation of the embedded shell.
3
4 from IPython import embed
5
6 a = 10
7 b = 20
8
9 embed('First time')
10
11 c = 30
12 d = 40
13
14 try:
15 raise Exception('adsfasdf')
16 except:
17 embed('The second time')
@@ -0,0 +1,59 b''
1 ====================================================
2 Notes on code execution in :class:`InteractiveShell`
3 ====================================================
4
5 Overview
6 ========
7
8 This section contains information and notes about the code execution
9 system in :class:`InteractiveShell`. This system needs to be refactored
10 and we are keeping notes about this process here.
11
12 Current design
13 ==============
14
15 Here is a script that shows the relationships between the various
16 methods in :class:`InteractiveShell` that manage code execution::
17
18 import networkx as nx
19 import matplotlib.pyplot as plt
20
21 exec_init_cmd = 'exec_init_cmd'
22 interact = 'interact'
23 runlines = 'runlines'
24 runsource = 'runsource'
25 runcode = 'runcode'
26 push_line = 'push_line'
27 mainloop = 'mainloop'
28 embed_mainloop = 'embed_mainloop'
29 ri = 'raw_input'
30 prefilter = 'prefilter'
31
32 g = nx.DiGraph()
33
34 g.add_node(exec_init_cmd)
35 g.add_node(interact)
36 g.add_node(runlines)
37 g.add_node(runsource)
38 g.add_node(push_line)
39 g.add_node(mainloop)
40 g.add_node(embed_mainloop)
41 g.add_node(ri)
42 g.add_node(prefilter)
43
44 g.add_edge(exec_init_cmd, push_line)
45 g.add_edge(exec_init_cmd, prefilter)
46 g.add_edge(mainloop, exec_init_cmd)
47 g.add_edge(mainloop, interact)
48 g.add_edge(embed_mainloop, interact)
49 g.add_edge(interact, ri)
50 g.add_edge(interact, push_line)
51 g.add_edge(push_line, runsource)
52 g.add_edge(runlines, push_line)
53 g.add_edge(runlines, prefilter)
54 g.add_edge(runsource, runcode)
55 g.add_edge(ri, prefilter)
56
57 nx.draw_spectral(g, node_size=100, alpha=0.6, node_color='r',
58 font_size=10, node_shape='o')
59 plt.show()
@@ -15,4 +15,5 b" IPython developer's guide"
15 roadmap.txt
15 roadmap.txt
16 reorg.txt
16 reorg.txt
17 notification_blueprint.txt
17 notification_blueprint.txt
18 ipgraph.txt
18
19
General Comments 0
You need to be logged in to leave comments. Login now