Show More
@@ -72,10 +72,10 b' class MyApp(Application):' | |||||
72 | )) |
|
72 | )) | |
73 |
|
73 | |||
74 | def init_foo(self): |
|
74 | def init_foo(self): | |
75 |
self.foo = Foo( |
|
75 | self.foo = Foo(parent=self) | |
76 |
|
76 | |||
77 | def init_bar(self): |
|
77 | def init_bar(self): | |
78 |
self.bar = Bar( |
|
78 | self.bar = Bar(parent=self) | |
79 |
|
79 | |||
80 |
|
80 | |||
81 | class TestApplication(TestCase): |
|
81 | class TestApplication(TestCase): |
@@ -341,7 +341,7 b' class IPythonConsoleApp(Configurable):' | |||||
341 | stdin_port=self.stdin_port, |
|
341 | stdin_port=self.stdin_port, | |
342 | hb_port=self.hb_port, |
|
342 | hb_port=self.hb_port, | |
343 | connection_file=self.connection_file, |
|
343 | connection_file=self.connection_file, | |
344 |
|
|
344 | parent=self, | |
345 | ) |
|
345 | ) | |
346 | self.kernel_manager.client_factory = self.kernel_client_class |
|
346 | self.kernel_manager.client_factory = self.kernel_client_class | |
347 | self.kernel_manager.start_kernel(extra_arguments=self.kernel_argv) |
|
347 | self.kernel_manager.start_kernel(extra_arguments=self.kernel_argv) | |
@@ -371,7 +371,7 b' class IPythonConsoleApp(Configurable):' | |||||
371 | stdin_port=self.stdin_port, |
|
371 | stdin_port=self.stdin_port, | |
372 | hb_port=self.hb_port, |
|
372 | hb_port=self.hb_port, | |
373 | connection_file=self.connection_file, |
|
373 | connection_file=self.connection_file, | |
374 |
|
|
374 | parent=self, | |
375 | ) |
|
375 | ) | |
376 |
|
376 | |||
377 | self.kernel_client.start_channels() |
|
377 | self.kernel_client.start_channels() |
@@ -114,8 +114,8 b' class AliasManager(Configurable):' | |||||
114 | user_aliases = List(default_value=[], config=True) |
|
114 | user_aliases = List(default_value=[], config=True) | |
115 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') |
|
115 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') | |
116 |
|
116 | |||
117 |
def __init__(self, shell=None, |
|
117 | def __init__(self, shell=None, **kwargs): | |
118 |
super(AliasManager, self).__init__(shell=shell, |
|
118 | super(AliasManager, self).__init__(shell=shell, **kwargs) | |
119 | self.alias_table = {} |
|
119 | self.alias_table = {} | |
120 | self.exclude_aliases() |
|
120 | self.exclude_aliases() | |
121 | self.init_aliases() |
|
121 | self.init_aliases() |
@@ -246,7 +246,7 b' class Completer(Configurable):' | |||||
246 | ) |
|
246 | ) | |
247 |
|
247 | |||
248 |
|
248 | |||
249 |
def __init__(self, namespace=None, global_namespace=None, |
|
249 | def __init__(self, namespace=None, global_namespace=None, **kwargs): | |
250 | """Create a new completer for the command line. |
|
250 | """Create a new completer for the command line. | |
251 |
|
251 | |||
252 | Completer(namespace=ns,global_namespace=ns2) -> completer instance. |
|
252 | Completer(namespace=ns,global_namespace=ns2) -> completer instance. | |
@@ -280,7 +280,7 b' class Completer(Configurable):' | |||||
280 | else: |
|
280 | else: | |
281 | self.global_namespace = global_namespace |
|
281 | self.global_namespace = global_namespace | |
282 |
|
282 | |||
283 |
super(Completer, self).__init__( |
|
283 | super(Completer, self).__init__(**kwargs) | |
284 |
|
284 | |||
285 | def complete(self, text, state): |
|
285 | def complete(self, text, state): | |
286 | """Return the next possible completion for 'text'. |
|
286 | """Return the next possible completion for 'text'. |
@@ -50,8 +50,8 b' class DisplayHook(Configurable):' | |||||
50 |
|
50 | |||
51 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') |
|
51 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') | |
52 |
|
52 | |||
53 |
def __init__(self, shell=None, cache_size=1000, |
|
53 | def __init__(self, shell=None, cache_size=1000, **kwargs): | |
54 |
super(DisplayHook, self).__init__(shell=shell, |
|
54 | super(DisplayHook, self).__init__(shell=shell, **kwargs) | |
55 |
|
55 | |||
56 | cache_size_min = 3 |
|
56 | cache_size_min = 3 | |
57 | if cache_size <= 0: |
|
57 | if cache_size <= 0: |
@@ -47,7 +47,7 b' class ExtensionManager(Configurable):' | |||||
47 | that point, including defining new magic and aliases, adding new |
|
47 | that point, including defining new magic and aliases, adding new | |
48 | components, etc. |
|
48 | components, etc. | |
49 |
|
49 | |||
50 | You can also optionaly define an :func:`unload_ipython_extension(ipython)` |
|
50 | You can also optionally define an :func:`unload_ipython_extension(ipython)` | |
51 | function, which will be called if the user unloads or reloads the extension. |
|
51 | function, which will be called if the user unloads or reloads the extension. | |
52 | The extension manager will only call :func:`load_ipython_extension` again |
|
52 | The extension manager will only call :func:`load_ipython_extension` again | |
53 | if the extension is reloaded. |
|
53 | if the extension is reloaded. | |
@@ -61,8 +61,8 b' class ExtensionManager(Configurable):' | |||||
61 |
|
61 | |||
62 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') |
|
62 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') | |
63 |
|
63 | |||
64 |
def __init__(self, shell=None, |
|
64 | def __init__(self, shell=None, **kwargs): | |
65 |
super(ExtensionManager, self).__init__(shell=shell, |
|
65 | super(ExtensionManager, self).__init__(shell=shell, **kwargs) | |
66 | self.shell.on_trait_change( |
|
66 | self.shell.on_trait_change( | |
67 | self._on_ipython_dir_changed, 'ipython_dir' |
|
67 | self._on_ipython_dir_changed, 'ipython_dir' | |
68 | ) |
|
68 | ) |
@@ -92,7 +92,7 b' class DisplayFormatter(Configurable):' | |||||
92 | ] |
|
92 | ] | |
93 | d = {} |
|
93 | d = {} | |
94 | for cls in formatter_classes: |
|
94 | for cls in formatter_classes: | |
95 |
f = cls( |
|
95 | f = cls(parent=self) | |
96 | d[f.format_type] = f |
|
96 | d[f.format_type] = f | |
97 | return d |
|
97 | return d | |
98 |
|
98 |
@@ -148,7 +148,7 b' class HistoryAccessor(Configurable):' | |||||
148 | (self.__class__.__name__, new) |
|
148 | (self.__class__.__name__, new) | |
149 | raise TraitError(msg) |
|
149 | raise TraitError(msg) | |
150 |
|
150 | |||
151 |
def __init__(self, profile='default', hist_file=u'', |
|
151 | def __init__(self, profile='default', hist_file=u'', **traits): | |
152 | """Create a new history accessor. |
|
152 | """Create a new history accessor. | |
153 |
|
153 | |||
154 | Parameters |
|
154 | Parameters | |
@@ -162,7 +162,7 b' class HistoryAccessor(Configurable):' | |||||
162 | Config object. hist_file can also be set through this. |
|
162 | Config object. hist_file can also be set through this. | |
163 | """ |
|
163 | """ | |
164 | # We need a pointer back to the shell for various tasks. |
|
164 | # We need a pointer back to the shell for various tasks. | |
165 |
super(HistoryAccessor, self).__init__( |
|
165 | super(HistoryAccessor, self).__init__(**traits) | |
166 | # defer setting hist_file from kwarg until after init, |
|
166 | # defer setting hist_file from kwarg until after init, | |
167 | # otherwise the default kwarg value would clobber any value |
|
167 | # otherwise the default kwarg value would clobber any value | |
168 | # set by config |
|
168 | # set by config |
@@ -419,13 +419,13 b' class InteractiveShell(SingletonConfigurable):' | |||||
419 | # Tracks any GUI loop loaded for pylab |
|
419 | # Tracks any GUI loop loaded for pylab | |
420 | pylab_gui_select = None |
|
420 | pylab_gui_select = None | |
421 |
|
421 | |||
422 |
def __init__(self |
|
422 | def __init__(self, ipython_dir=None, profile_dir=None, | |
423 | user_module=None, user_ns=None, |
|
423 | user_module=None, user_ns=None, | |
424 | custom_exceptions=((), None), **kwargs): |
|
424 | custom_exceptions=((), None), **kwargs): | |
425 |
|
425 | |||
426 | # This is where traits with a config_key argument are updated |
|
426 | # This is where traits with a config_key argument are updated | |
427 | # from the values on config. |
|
427 | # from the values on config. | |
428 |
super(InteractiveShell, self).__init__( |
|
428 | super(InteractiveShell, self).__init__(**kwargs) | |
429 | self.configurables = [self] |
|
429 | self.configurables = [self] | |
430 |
|
430 | |||
431 | # These are relatively independent and stateless |
|
431 | # These are relatively independent and stateless | |
@@ -651,7 +651,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
651 | io.stderr = io.IOStream(sys.stderr) |
|
651 | io.stderr = io.IOStream(sys.stderr) | |
652 |
|
652 | |||
653 | def init_prompts(self): |
|
653 | def init_prompts(self): | |
654 |
self.prompt_manager = PromptManager(shell=self, |
|
654 | self.prompt_manager = PromptManager(shell=self, parent=self) | |
655 | self.configurables.append(self.prompt_manager) |
|
655 | self.configurables.append(self.prompt_manager) | |
656 | # Set system prompts, so that scripts can decide if they are running |
|
656 | # Set system prompts, so that scripts can decide if they are running | |
657 | # interactively. |
|
657 | # interactively. | |
@@ -660,24 +660,24 b' class InteractiveShell(SingletonConfigurable):' | |||||
660 | sys.ps3 = 'Out: ' |
|
660 | sys.ps3 = 'Out: ' | |
661 |
|
661 | |||
662 | def init_display_formatter(self): |
|
662 | def init_display_formatter(self): | |
663 |
self.display_formatter = DisplayFormatter( |
|
663 | self.display_formatter = DisplayFormatter(parent=self) | |
664 | self.configurables.append(self.display_formatter) |
|
664 | self.configurables.append(self.display_formatter) | |
665 |
|
665 | |||
666 | def init_display_pub(self): |
|
666 | def init_display_pub(self): | |
667 |
self.display_pub = self.display_pub_class( |
|
667 | self.display_pub = self.display_pub_class(parent=self) | |
668 | self.configurables.append(self.display_pub) |
|
668 | self.configurables.append(self.display_pub) | |
669 |
|
669 | |||
670 | def init_data_pub(self): |
|
670 | def init_data_pub(self): | |
671 | if not self.data_pub_class: |
|
671 | if not self.data_pub_class: | |
672 | self.data_pub = None |
|
672 | self.data_pub = None | |
673 | return |
|
673 | return | |
674 |
self.data_pub = self.data_pub_class( |
|
674 | self.data_pub = self.data_pub_class(parent=self) | |
675 | self.configurables.append(self.data_pub) |
|
675 | self.configurables.append(self.data_pub) | |
676 |
|
676 | |||
677 | def init_displayhook(self): |
|
677 | def init_displayhook(self): | |
678 | # Initialize displayhook, set in/out prompts and printing system |
|
678 | # Initialize displayhook, set in/out prompts and printing system | |
679 | self.displayhook = self.displayhook_class( |
|
679 | self.displayhook = self.displayhook_class( | |
680 |
|
|
680 | parent=self, | |
681 | shell=self, |
|
681 | shell=self, | |
682 | cache_size=self.cache_size, |
|
682 | cache_size=self.cache_size, | |
683 | ) |
|
683 | ) | |
@@ -688,7 +688,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
688 |
|
688 | |||
689 | def init_latextool(self): |
|
689 | def init_latextool(self): | |
690 | """Configure LaTeXTool.""" |
|
690 | """Configure LaTeXTool.""" | |
691 |
cfg = LaTeXTool.instance( |
|
691 | cfg = LaTeXTool.instance(parent=self) | |
692 | if cfg not in self.configurables: |
|
692 | if cfg not in self.configurables: | |
693 | self.configurables.append(cfg) |
|
693 | self.configurables.append(cfg) | |
694 |
|
694 | |||
@@ -1511,7 +1511,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
1511 |
|
1511 | |||
1512 | def init_history(self): |
|
1512 | def init_history(self): | |
1513 | """Sets up the command history, and starts regular autosaves.""" |
|
1513 | """Sets up the command history, and starts regular autosaves.""" | |
1514 |
self.history_manager = HistoryManager(shell=self, |
|
1514 | self.history_manager = HistoryManager(shell=self, parent=self) | |
1515 | self.configurables.append(self.history_manager) |
|
1515 | self.configurables.append(self.history_manager) | |
1516 |
|
1516 | |||
1517 | #------------------------------------------------------------------------- |
|
1517 | #------------------------------------------------------------------------- | |
@@ -1943,7 +1943,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
1943 | global_namespace=self.user_global_ns, |
|
1943 | global_namespace=self.user_global_ns, | |
1944 | alias_table=self.alias_manager.alias_table, |
|
1944 | alias_table=self.alias_manager.alias_table, | |
1945 | use_readline=self.has_readline, |
|
1945 | use_readline=self.has_readline, | |
1946 |
|
|
1946 | parent=self, | |
1947 | ) |
|
1947 | ) | |
1948 | self.configurables.append(self.Completer) |
|
1948 | self.configurables.append(self.Completer) | |
1949 |
|
1949 | |||
@@ -2038,7 +2038,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
2038 | def init_magics(self): |
|
2038 | def init_magics(self): | |
2039 | from IPython.core import magics as m |
|
2039 | from IPython.core import magics as m | |
2040 | self.magics_manager = magic.MagicsManager(shell=self, |
|
2040 | self.magics_manager = magic.MagicsManager(shell=self, | |
2041 |
|
|
2041 | parent=self, | |
2042 | user_magics=m.UserMagics(self)) |
|
2042 | user_magics=m.UserMagics(self)) | |
2043 | self.configurables.append(self.magics_manager) |
|
2043 | self.configurables.append(self.magics_manager) | |
2044 |
|
2044 | |||
@@ -2299,7 +2299,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
2299 | #------------------------------------------------------------------------- |
|
2299 | #------------------------------------------------------------------------- | |
2300 |
|
2300 | |||
2301 | def init_alias(self): |
|
2301 | def init_alias(self): | |
2302 |
self.alias_manager = AliasManager(shell=self, |
|
2302 | self.alias_manager = AliasManager(shell=self, parent=self) | |
2303 | self.configurables.append(self.alias_manager) |
|
2303 | self.configurables.append(self.alias_manager) | |
2304 | self.ns_table['alias'] = self.alias_manager.alias_table, |
|
2304 | self.ns_table['alias'] = self.alias_manager.alias_table, | |
2305 |
|
2305 | |||
@@ -2308,7 +2308,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
2308 | #------------------------------------------------------------------------- |
|
2308 | #------------------------------------------------------------------------- | |
2309 |
|
2309 | |||
2310 | def init_extension_manager(self): |
|
2310 | def init_extension_manager(self): | |
2311 |
self.extension_manager = ExtensionManager(shell=self, |
|
2311 | self.extension_manager = ExtensionManager(shell=self, parent=self) | |
2312 | self.configurables.append(self.extension_manager) |
|
2312 | self.configurables.append(self.extension_manager) | |
2313 |
|
2313 | |||
2314 | #------------------------------------------------------------------------- |
|
2314 | #------------------------------------------------------------------------- | |
@@ -2316,7 +2316,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
2316 | #------------------------------------------------------------------------- |
|
2316 | #------------------------------------------------------------------------- | |
2317 |
|
2317 | |||
2318 | def init_payload(self): |
|
2318 | def init_payload(self): | |
2319 |
self.payload_manager = PayloadManager( |
|
2319 | self.payload_manager = PayloadManager(parent=self) | |
2320 | self.configurables.append(self.payload_manager) |
|
2320 | self.configurables.append(self.payload_manager) | |
2321 |
|
2321 | |||
2322 | #------------------------------------------------------------------------- |
|
2322 | #------------------------------------------------------------------------- | |
@@ -2324,7 +2324,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
2324 | #------------------------------------------------------------------------- |
|
2324 | #------------------------------------------------------------------------- | |
2325 |
|
2325 | |||
2326 | def init_prefilter(self): |
|
2326 | def init_prefilter(self): | |
2327 |
self.prefilter_manager = PrefilterManager(shell=self, |
|
2327 | self.prefilter_manager = PrefilterManager(shell=self, parent=self) | |
2328 | self.configurables.append(self.prefilter_manager) |
|
2328 | self.configurables.append(self.prefilter_manager) | |
2329 | # Ultimately this will be refactored in the new interpreter code, but |
|
2329 | # Ultimately this will be refactored in the new interpreter code, but | |
2330 | # for now, we should expose the main prefilter method (there's legacy |
|
2330 | # for now, we should expose the main prefilter method (there's legacy |
@@ -134,8 +134,8 b' class PrefilterManager(Configurable):' | |||||
134 | multi_line_specials = CBool(True, config=True) |
|
134 | multi_line_specials = CBool(True, config=True) | |
135 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') |
|
135 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') | |
136 |
|
136 | |||
137 |
def __init__(self, shell=None, |
|
137 | def __init__(self, shell=None, **kwargs): | |
138 |
super(PrefilterManager, self).__init__(shell=shell, |
|
138 | super(PrefilterManager, self).__init__(shell=shell, **kwargs) | |
139 | self.shell = shell |
|
139 | self.shell = shell | |
140 | self.init_transformers() |
|
140 | self.init_transformers() | |
141 | self.init_handlers() |
|
141 | self.init_handlers() | |
@@ -150,7 +150,7 b' class PrefilterManager(Configurable):' | |||||
150 | self._transformers = [] |
|
150 | self._transformers = [] | |
151 | for transformer_cls in _default_transformers: |
|
151 | for transformer_cls in _default_transformers: | |
152 | transformer_cls( |
|
152 | transformer_cls( | |
153 |
shell=self.shell, prefilter_manager=self, |
|
153 | shell=self.shell, prefilter_manager=self, parent=self | |
154 | ) |
|
154 | ) | |
155 |
|
155 | |||
156 | def sort_transformers(self): |
|
156 | def sort_transformers(self): | |
@@ -186,7 +186,7 b' class PrefilterManager(Configurable):' | |||||
186 | self._checkers = [] |
|
186 | self._checkers = [] | |
187 | for checker in _default_checkers: |
|
187 | for checker in _default_checkers: | |
188 | checker( |
|
188 | checker( | |
189 |
shell=self.shell, prefilter_manager=self, |
|
189 | shell=self.shell, prefilter_manager=self, parent=self | |
190 | ) |
|
190 | ) | |
191 |
|
191 | |||
192 | def sort_checkers(self): |
|
192 | def sort_checkers(self): | |
@@ -223,7 +223,7 b' class PrefilterManager(Configurable):' | |||||
223 | self._esc_handlers = {} |
|
223 | self._esc_handlers = {} | |
224 | for handler in _default_handlers: |
|
224 | for handler in _default_handlers: | |
225 | handler( |
|
225 | handler( | |
226 |
shell=self.shell, prefilter_manager=self, |
|
226 | shell=self.shell, prefilter_manager=self, parent=self | |
227 | ) |
|
227 | ) | |
228 |
|
228 | |||
229 | @property |
|
229 | @property | |
@@ -368,9 +368,9 b' class PrefilterTransformer(Configurable):' | |||||
368 | prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager') |
|
368 | prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager') | |
369 | enabled = Bool(True, config=True) |
|
369 | enabled = Bool(True, config=True) | |
370 |
|
370 | |||
371 |
def __init__(self, shell=None, prefilter_manager=None, |
|
371 | def __init__(self, shell=None, prefilter_manager=None, **kwargs): | |
372 | super(PrefilterTransformer, self).__init__( |
|
372 | super(PrefilterTransformer, self).__init__( | |
373 |
shell=shell, prefilter_manager=prefilter_manager, |
|
373 | shell=shell, prefilter_manager=prefilter_manager, **kwargs | |
374 | ) |
|
374 | ) | |
375 | self.prefilter_manager.register_transformer(self) |
|
375 | self.prefilter_manager.register_transformer(self) | |
376 |
|
376 | |||
@@ -396,9 +396,9 b' class PrefilterChecker(Configurable):' | |||||
396 | prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager') |
|
396 | prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager') | |
397 | enabled = Bool(True, config=True) |
|
397 | enabled = Bool(True, config=True) | |
398 |
|
398 | |||
399 |
def __init__(self, shell=None, prefilter_manager=None, |
|
399 | def __init__(self, shell=None, prefilter_manager=None, **kwargs): | |
400 | super(PrefilterChecker, self).__init__( |
|
400 | super(PrefilterChecker, self).__init__( | |
401 |
shell=shell, prefilter_manager=prefilter_manager, |
|
401 | shell=shell, prefilter_manager=prefilter_manager, **kwargs | |
402 | ) |
|
402 | ) | |
403 | self.prefilter_manager.register_checker(self) |
|
403 | self.prefilter_manager.register_checker(self) | |
404 |
|
404 | |||
@@ -561,9 +561,9 b' class PrefilterHandler(Configurable):' | |||||
561 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') |
|
561 | shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') | |
562 | prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager') |
|
562 | prefilter_manager = Instance('IPython.core.prefilter.PrefilterManager') | |
563 |
|
563 | |||
564 |
def __init__(self, shell=None, prefilter_manager=None, |
|
564 | def __init__(self, shell=None, prefilter_manager=None, **kwargs): | |
565 | super(PrefilterHandler, self).__init__( |
|
565 | super(PrefilterHandler, self).__init__( | |
566 |
shell=shell, prefilter_manager=prefilter_manager, |
|
566 | shell=shell, prefilter_manager=prefilter_manager, **kwargs | |
567 | ) |
|
567 | ) | |
568 | self.prefilter_manager.register_handler( |
|
568 | self.prefilter_manager.register_handler( | |
569 | self.handler_name, |
|
569 | self.handler_name, |
@@ -318,8 +318,8 b' class PromptManager(Configurable):' | |||||
318 | def _invisible_chars_default(self): |
|
318 | def _invisible_chars_default(self): | |
319 | return {'in': 0, 'in2': 0, 'out': 0, 'rewrite':0} |
|
319 | return {'in': 0, 'in2': 0, 'out': 0, 'rewrite':0} | |
320 |
|
320 | |||
321 |
def __init__(self, shell, |
|
321 | def __init__(self, shell, **kwargs): | |
322 |
super(PromptManager, self).__init__(shell=shell, |
|
322 | super(PromptManager, self).__init__(shell=shell, **kwargs) | |
323 |
|
323 | |||
324 | # Prepare colour scheme table |
|
324 | # Prepare colour scheme table | |
325 | self.color_scheme_table = coloransi.ColorSchemeTable([PColNoColors, |
|
325 | self.color_scheme_table = coloransi.ColorSchemeTable([PColNoColors, |
@@ -283,7 +283,7 b' def configure_inline_support(shell, backend, user_ns=None):' | |||||
283 |
|
283 | |||
284 | user_ns = shell.user_ns if user_ns is None else user_ns |
|
284 | user_ns = shell.user_ns if user_ns is None else user_ns | |
285 |
|
285 | |||
286 |
cfg = InlineBackend.instance( |
|
286 | cfg = InlineBackend.instance(parent=shell) | |
287 | cfg.shell = shell |
|
287 | cfg.shell = shell | |
288 | if cfg not in shell.configurables: |
|
288 | if cfg not in shell.configurables: | |
289 | shell.configurables.append(cfg) |
|
289 | shell.configurables.append(cfg) |
@@ -84,7 +84,7 b' class AuthenticatedZMQStreamHandler(ZMQStreamHandler, IPythonHandler):' | |||||
84 |
|
84 | |||
85 | def open(self, kernel_id): |
|
85 | def open(self, kernel_id): | |
86 | self.kernel_id = kernel_id.decode('ascii') |
|
86 | self.kernel_id = kernel_id.decode('ascii') | |
87 |
self.session = Session( |
|
87 | self.session = Session(parent=self) | |
88 | self.save_on_message = self.on_message |
|
88 | self.save_on_message = self.on_message | |
89 | self.on_message = self.on_first_message |
|
89 | self.on_message = self.on_first_message | |
90 |
|
90 |
@@ -522,13 +522,13 b' class NotebookApp(BaseIPythonApplication):' | |||||
522 | # force Session default to be secure |
|
522 | # force Session default to be secure | |
523 | default_secure(self.config) |
|
523 | default_secure(self.config) | |
524 | self.kernel_manager = MappingKernelManager( |
|
524 | self.kernel_manager = MappingKernelManager( | |
525 |
|
|
525 | parent=self, log=self.log, kernel_argv=self.kernel_argv, | |
526 | connection_dir = self.profile_dir.security_dir, |
|
526 | connection_dir = self.profile_dir.security_dir, | |
527 | ) |
|
527 | ) | |
528 | kls = import_item(self.notebook_manager_class) |
|
528 | kls = import_item(self.notebook_manager_class) | |
529 |
self.notebook_manager = kls( |
|
529 | self.notebook_manager = kls(parent=self, log=self.log) | |
530 | self.notebook_manager.load_notebook_names() |
|
530 | self.notebook_manager.load_notebook_names() | |
531 |
self.cluster_manager = ClusterManager( |
|
531 | self.cluster_manager = ClusterManager(parent=self, log=self.log) | |
532 | self.cluster_manager.update_profiles() |
|
532 | self.cluster_manager.update_profiles() | |
533 |
|
533 | |||
534 | def init_logging(self): |
|
534 | def init_logging(self): |
@@ -59,7 +59,7 b' class KernelClient(LoggingConfigurable, ConnectionFileMixin):' | |||||
59 | # The Session to use for communication with the kernel. |
|
59 | # The Session to use for communication with the kernel. | |
60 | session = Instance(Session) |
|
60 | session = Instance(Session) | |
61 | def _session_default(self): |
|
61 | def _session_default(self): | |
62 |
return Session( |
|
62 | return Session(parent=self) | |
63 |
|
63 | |||
64 | # The classes to use for the various channels |
|
64 | # The classes to use for the various channels | |
65 | shell_channel_class = Type(ShellChannel) |
|
65 | shell_channel_class = Type(ShellChannel) |
@@ -134,7 +134,7 b' class InProcessKernel(Kernel):' | |||||
134 |
|
134 | |||
135 | def _session_default(self): |
|
135 | def _session_default(self): | |
136 | from IPython.kernel.zmq.session import Session |
|
136 | from IPython.kernel.zmq.session import Session | |
137 |
return Session( |
|
137 | return Session(parent=self) | |
138 |
|
138 | |||
139 | def _shell_class_default(self): |
|
139 | def _shell_class_default(self): | |
140 | return InProcessInteractiveShell |
|
140 | return InProcessInteractiveShell |
@@ -48,7 +48,7 b' class IOLoopKernelManager(KernelManager):' | |||||
48 | if self._restarter is None: |
|
48 | if self._restarter is None: | |
49 | self._restarter = IOLoopKernelRestarter( |
|
49 | self._restarter = IOLoopKernelRestarter( | |
50 | kernel_manager=self, loop=self.loop, |
|
50 | kernel_manager=self, loop=self.loop, | |
51 |
|
|
51 | parent=self, log=self.log | |
52 | ) |
|
52 | ) | |
53 | self._restarter.start() |
|
53 | self._restarter.start() | |
54 |
|
54 |
@@ -56,7 +56,7 b' class KernelManager(LoggingConfigurable, ConnectionFileMixin):' | |||||
56 | # The Session to use for communication with the kernel. |
|
56 | # The Session to use for communication with the kernel. | |
57 | session = Instance(Session) |
|
57 | session = Instance(Session) | |
58 | def _session_default(self): |
|
58 | def _session_default(self): | |
59 |
return Session( |
|
59 | return Session(parent=self) | |
60 |
|
60 | |||
61 | # the class to create with our `client` method |
|
61 | # the class to create with our `client` method | |
62 | client_class = DottedObjectName('IPython.kernel.blocking.BlockingKernelClient') |
|
62 | client_class = DottedObjectName('IPython.kernel.blocking.BlockingKernelClient') | |
@@ -129,7 +129,7 b' class KernelManager(LoggingConfigurable, ConnectionFileMixin):' | |||||
129 | kw.update(dict( |
|
129 | kw.update(dict( | |
130 | connection_file=self.connection_file, |
|
130 | connection_file=self.connection_file, | |
131 | session=self.session, |
|
131 | session=self.session, | |
132 |
|
|
132 | parent=self, | |
133 | )) |
|
133 | )) | |
134 |
|
134 | |||
135 | # add kwargs last, for manual overrides |
|
135 | # add kwargs last, for manual overrides |
@@ -110,7 +110,7 b' class MultiKernelManager(LoggingConfigurable):' | |||||
110 | # including things like its transport and ip. |
|
110 | # including things like its transport and ip. | |
111 | km = self.kernel_manager_factory(connection_file=os.path.join( |
|
111 | km = self.kernel_manager_factory(connection_file=os.path.join( | |
112 | self.connection_dir, "kernel-%s.json" % kernel_id), |
|
112 | self.connection_dir, "kernel-%s.json" % kernel_id), | |
113 |
|
|
113 | parent=self, autorestart=True, log=self.log | |
114 | ) |
|
114 | ) | |
115 | km.start_kernel(**kwargs) |
|
115 | km.start_kernel(**kwargs) | |
116 | self._kernels[kernel_id] = km |
|
116 | self._kernels[kernel_id] = km |
@@ -141,7 +141,7 b' class Kernel(Configurable):' | |||||
141 | super(Kernel, self).__init__(**kwargs) |
|
141 | super(Kernel, self).__init__(**kwargs) | |
142 |
|
142 | |||
143 | # Initialize the InteractiveShell subclass |
|
143 | # Initialize the InteractiveShell subclass | |
144 |
self.shell = self.shell_class.instance( |
|
144 | self.shell = self.shell_class.instance(parent=self, | |
145 | profile_dir = self.profile_dir, |
|
145 | profile_dir = self.profile_dir, | |
146 | user_module = self.user_module, |
|
146 | user_module = self.user_module, | |
147 | user_ns = self.user_ns, |
|
147 | user_ns = self.user_ns, |
@@ -71,7 +71,7 b' kernel_aliases.update({' | |||||
71 | 'stdin' : 'IPKernelApp.stdin_port', |
|
71 | 'stdin' : 'IPKernelApp.stdin_port', | |
72 | 'control' : 'IPKernelApp.control_port', |
|
72 | 'control' : 'IPKernelApp.control_port', | |
73 | 'f' : 'IPKernelApp.connection_file', |
|
73 | 'f' : 'IPKernelApp.connection_file', | |
74 | 'parent': 'IPKernelApp.parent', |
|
74 | 'parent': 'IPKernelApp.parent_handle', | |
75 | 'transport': 'IPKernelApp.transport', |
|
75 | 'transport': 'IPKernelApp.transport', | |
76 | }) |
|
76 | }) | |
77 | if sys.platform.startswith('win'): |
|
77 | if sys.platform.startswith('win'): | |
@@ -172,7 +172,7 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp):' | |||||
172 | config=True, help="The importstring for the DisplayHook factory") |
|
172 | config=True, help="The importstring for the DisplayHook factory") | |
173 |
|
173 | |||
174 | # polling |
|
174 | # polling | |
175 | parent = Integer(0, config=True, |
|
175 | parent_handle = Integer(0, config=True, | |
176 | help="""kill this process if its parent dies. On Windows, the argument |
|
176 | help="""kill this process if its parent dies. On Windows, the argument | |
177 | specifies the HANDLE of the parent process, otherwise it is simply boolean. |
|
177 | specifies the HANDLE of the parent process, otherwise it is simply boolean. | |
178 | """) |
|
178 | """) | |
@@ -188,9 +188,9 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp):' | |||||
188 |
|
188 | |||
189 | def init_poller(self): |
|
189 | def init_poller(self): | |
190 | if sys.platform == 'win32': |
|
190 | if sys.platform == 'win32': | |
191 | if self.interrupt or self.parent: |
|
191 | if self.interrupt or self.parent_handle: | |
192 | self.poller = ParentPollerWindows(self.interrupt, self.parent) |
|
192 | self.poller = ParentPollerWindows(self.interrupt, self.parent_handle) | |
193 | elif self.parent: |
|
193 | elif self.parent_handle: | |
194 | self.poller = ParentPollerUnix() |
|
194 | self.poller = ParentPollerUnix() | |
195 |
|
195 | |||
196 | def _bind_socket(self, s, port): |
|
196 | def _bind_socket(self, s, port): | |
@@ -329,8 +329,8 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp):' | |||||
329 | # to see the connection info |
|
329 | # to see the connection info | |
330 | for line in lines: |
|
330 | for line in lines: | |
331 | self.log.info(line) |
|
331 | self.log.info(line) | |
332 | # also raw print to the terminal if no parent (`ipython kernel`) |
|
332 | # also raw print to the terminal if no parent_handle (`ipython kernel`) | |
333 | if not self.parent: |
|
333 | if not self.parent_handle: | |
334 | for line in lines: |
|
334 | for line in lines: | |
335 | io.rprint(line) |
|
335 | io.rprint(line) | |
336 |
|
336 | |||
@@ -341,7 +341,7 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp):' | |||||
341 | def init_session(self): |
|
341 | def init_session(self): | |
342 | """create our session object""" |
|
342 | """create our session object""" | |
343 | default_secure(self.config) |
|
343 | default_secure(self.config) | |
344 |
self.session = Session( |
|
344 | self.session = Session(parent=self, username=u'kernel') | |
345 |
|
345 | |||
346 | def init_blackhole(self): |
|
346 | def init_blackhole(self): | |
347 | """redirects stdout/stderr to devnull if necessary""" |
|
347 | """redirects stdout/stderr to devnull if necessary""" | |
@@ -372,7 +372,7 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp):' | |||||
372 |
|
372 | |||
373 | kernel_factory = import_item(str(self.kernel_class)) |
|
373 | kernel_factory = import_item(str(self.kernel_class)) | |
374 |
|
374 | |||
375 |
kernel = kernel_factory( |
|
375 | kernel = kernel_factory(parent=self, session=self.session, | |
376 | shell_streams=[shell_stream, control_stream], |
|
376 | shell_streams=[shell_stream, control_stream], | |
377 | iopub_socket=self.iopub_socket, |
|
377 | iopub_socket=self.iopub_socket, | |
378 | stdin_socket=self.stdin_socket, |
|
378 | stdin_socket=self.stdin_socket, |
@@ -338,7 +338,7 b' class IPClusterEngines(BaseParallelApplication):' | |||||
338 | self.exit(1) |
|
338 | self.exit(1) | |
339 |
|
339 | |||
340 | launcher = klass( |
|
340 | launcher = klass( | |
341 |
work_dir=u'.', |
|
341 | work_dir=u'.', parent=self, log=self.log, | |
342 | profile_dir=self.profile_dir.location, cluster_id=self.cluster_id, |
|
342 | profile_dir=self.profile_dir.location, cluster_id=self.cluster_id, | |
343 | ) |
|
343 | ) | |
344 | return launcher |
|
344 | return launcher |
@@ -360,7 +360,7 b' class IPEngineApp(BaseParallelApplication):' | |||||
360 |
|
360 | |||
361 | def init_mpi(self): |
|
361 | def init_mpi(self): | |
362 | global mpi |
|
362 | global mpi | |
363 |
self.mpi = MPI( |
|
363 | self.mpi = MPI(parent=self) | |
364 |
|
364 | |||
365 | mpi_import_statement = self.mpi.init_script |
|
365 | mpi_import_statement = self.mpi.init_script | |
366 | if mpi_import_statement: |
|
366 | if mpi_import_statement: |
@@ -76,7 +76,7 b' class IPLoggerApp(BaseParallelApplication):' | |||||
76 |
|
76 | |||
77 | def init_watcher(self): |
|
77 | def init_watcher(self): | |
78 | try: |
|
78 | try: | |
79 |
self.watcher = LogWatcher( |
|
79 | self.watcher = LogWatcher(parent=self, log=self.log) | |
80 | except: |
|
80 | except: | |
81 | self.log.error("Couldn't start the LogWatcher", exc_info=True) |
|
81 | self.log.error("Couldn't start the LogWatcher", exc_info=True) | |
82 | self.exit(1) |
|
82 | self.exit(1) |
@@ -385,7 +385,7 b' class LocalEngineSetLauncher(LocalEngineLauncher):' | |||||
385 | for i in range(n): |
|
385 | for i in range(n): | |
386 | if i > 0: |
|
386 | if i > 0: | |
387 | time.sleep(self.delay) |
|
387 | time.sleep(self.delay) | |
388 |
el = self.launcher_class(work_dir=self.work_dir, |
|
388 | el = self.launcher_class(work_dir=self.work_dir, parent=self, log=self.log, | |
389 | profile_dir=self.profile_dir, cluster_id=self.cluster_id, |
|
389 | profile_dir=self.profile_dir, cluster_id=self.cluster_id, | |
390 | ) |
|
390 | ) | |
391 |
|
391 | |||
@@ -767,7 +767,7 b' class SSHEngineSetLauncher(LocalEngineSetLauncher):' | |||||
767 | for i in range(n): |
|
767 | for i in range(n): | |
768 | if i > 0: |
|
768 | if i > 0: | |
769 | time.sleep(self.delay) |
|
769 | time.sleep(self.delay) | |
770 |
el = self.launcher_class(work_dir=self.work_dir, |
|
770 | el = self.launcher_class(work_dir=self.work_dir, parent=self, log=self.log, | |
771 | profile_dir=self.profile_dir, cluster_id=self.cluster_id, |
|
771 | profile_dir=self.profile_dir, cluster_id=self.cluster_id, | |
772 | ) |
|
772 | ) | |
773 | if i > 0: |
|
773 | if i > 0: | |
@@ -922,9 +922,9 b' class WindowsHPCControllerLauncher(WindowsHPCLauncher, ClusterAppMixin):' | |||||
922 | help="extra args to pass to ipcontroller") |
|
922 | help="extra args to pass to ipcontroller") | |
923 |
|
923 | |||
924 | def write_job_file(self, n): |
|
924 | def write_job_file(self, n): | |
925 |
job = IPControllerJob( |
|
925 | job = IPControllerJob(parent=self) | |
926 |
|
926 | |||
927 |
t = IPControllerTask( |
|
927 | t = IPControllerTask(parent=self) | |
928 | # The tasks work directory is *not* the actual work directory of |
|
928 | # The tasks work directory is *not* the actual work directory of | |
929 | # the controller. It is used as the base path for the stdout/stderr |
|
929 | # the controller. It is used as the base path for the stdout/stderr | |
930 | # files that the scheduler redirects to. |
|
930 | # files that the scheduler redirects to. | |
@@ -954,10 +954,10 b' class WindowsHPCEngineSetLauncher(WindowsHPCLauncher, ClusterAppMixin):' | |||||
954 | help="extra args to pas to ipengine") |
|
954 | help="extra args to pas to ipengine") | |
955 |
|
955 | |||
956 | def write_job_file(self, n): |
|
956 | def write_job_file(self, n): | |
957 |
job = IPEngineSetJob( |
|
957 | job = IPEngineSetJob(parent=self) | |
958 |
|
958 | |||
959 | for i in range(n): |
|
959 | for i in range(n): | |
960 |
t = IPEngineTask( |
|
960 | t = IPEngineTask(parent=self) | |
961 | # The tasks work directory is *not* the actual work directory of |
|
961 | # The tasks work directory is *not* the actual work directory of | |
962 | # the engine. It is used as the base path for the stdout/stderr |
|
962 | # the engine. It is used as the base path for the stdout/stderr | |
963 | # files that the scheduler redirects to. |
|
963 | # files that the scheduler redirects to. |
@@ -300,7 +300,7 b' class HubFactory(RegistrationFactory):' | |||||
300 | hrep = ctx.socket(zmq.ROUTER) |
|
300 | hrep = ctx.socket(zmq.ROUTER) | |
301 | util.set_hwm(hrep, 0) |
|
301 | util.set_hwm(hrep, 0) | |
302 | hrep.bind(self.engine_url('hb_pong')) |
|
302 | hrep.bind(self.engine_url('hb_pong')) | |
303 |
self.heartmonitor = HeartMonitor(loop=loop, |
|
303 | self.heartmonitor = HeartMonitor(loop=loop, parent=self, log=self.log, | |
304 | pingstream=ZMQStream(hpub,loop), |
|
304 | pingstream=ZMQStream(hpub,loop), | |
305 | pongstream=ZMQStream(hrep,loop) |
|
305 | pongstream=ZMQStream(hrep,loop) | |
306 | ) |
|
306 | ) | |
@@ -324,7 +324,7 b' class HubFactory(RegistrationFactory):' | |||||
324 | db_class = _db_shortcuts.get(self.db_class.lower(), self.db_class) |
|
324 | db_class = _db_shortcuts.get(self.db_class.lower(), self.db_class) | |
325 | self.log.info('Hub using DB backend: %r', (db_class.split('.')[-1])) |
|
325 | self.log.info('Hub using DB backend: %r', (db_class.split('.')[-1])) | |
326 | self.db = import_item(str(db_class))(session=self.session.session, |
|
326 | self.db = import_item(str(db_class))(session=self.session.session, | |
327 |
|
|
327 | parent=self, log=self.log) | |
328 | time.sleep(.25) |
|
328 | time.sleep(.25) | |
329 |
|
329 | |||
330 | # resubmit stream |
|
330 | # resubmit stream |
@@ -230,7 +230,7 b' class EngineFactory(RegistrationFactory):' | |||||
230 | sys.displayhook = self.display_hook_factory(self.session, iopub_socket) |
|
230 | sys.displayhook = self.display_hook_factory(self.session, iopub_socket) | |
231 | sys.displayhook.topic = cast_bytes('engine.%i.pyout' % self.id) |
|
231 | sys.displayhook.topic = cast_bytes('engine.%i.pyout' % self.id) | |
232 |
|
232 | |||
233 |
self.kernel = Kernel( |
|
233 | self.kernel = Kernel(parent=self, int_id=self.id, ident=self.ident, session=self.session, | |
234 | control_stream=control_stream, shell_streams=shell_streams, iopub_socket=iopub_socket, |
|
234 | control_stream=control_stream, shell_streams=shell_streams, iopub_socket=iopub_socket, | |
235 | loop=loop, user_ns=self.user_ns, log=self.log) |
|
235 | loop=loop, user_ns=self.user_ns, log=self.log) | |
236 |
|
236 | |||
@@ -251,7 +251,7 b' class EngineFactory(RegistrationFactory):' | |||||
251 |
|
251 | |||
252 |
|
252 | |||
253 | # FIXME: This is a hack until IPKernelApp and IPEngineApp can be fully merged |
|
253 | # FIXME: This is a hack until IPKernelApp and IPEngineApp can be fully merged | |
254 |
app = IPKernelApp( |
|
254 | app = IPKernelApp(parent=self, shell=self.kernel.shell, kernel=self.kernel, log=self.log) | |
255 | app.init_profile_dir() |
|
255 | app.init_profile_dir() | |
256 | app.init_code() |
|
256 | app.init_code() | |
257 |
|
257 |
@@ -56,7 +56,7 b' class LauncherTest:' | |||||
56 | kw = dict( |
|
56 | kw = dict( | |
57 | work_dir=self.profile_dir, |
|
57 | work_dir=self.profile_dir, | |
58 | profile_dir=self.profile_dir, |
|
58 | profile_dir=self.profile_dir, | |
59 |
|
|
59 | parent=self, | |
60 | cluster_id='', |
|
60 | cluster_id='', | |
61 | log=logging.getLogger(), |
|
61 | log=logging.getLogger(), | |
62 | ) |
|
62 | ) |
@@ -196,7 +196,7 b' class IPythonQtConsoleApp(BaseIPythonApplication, IPythonConsoleApp):' | |||||
196 | """ |
|
196 | """ | |
197 | kernel_manager = self.kernel_manager_class( |
|
197 | kernel_manager = self.kernel_manager_class( | |
198 | connection_file=self._new_connection_file(), |
|
198 | connection_file=self._new_connection_file(), | |
199 |
|
|
199 | parent=self, | |
200 | autorestart=True, |
|
200 | autorestart=True, | |
201 | ) |
|
201 | ) | |
202 | # start the kernel |
|
202 | # start the kernel |
@@ -37,7 +37,7 b' class QtKernelManager(KernelManager, QtKernelManagerMixin):' | |||||
37 | if self._restarter is None: |
|
37 | if self._restarter is None: | |
38 | self._restarter = QtKernelRestarter( |
|
38 | self._restarter = QtKernelRestarter( | |
39 | kernel_manager=self, |
|
39 | kernel_manager=self, | |
40 |
|
|
40 | parent=self, | |
41 | log=self.log, |
|
41 | log=self.log, | |
42 | ) |
|
42 | ) | |
43 | self._restarter.add_callback(self._handle_kernel_restarted) |
|
43 | self._restarter.add_callback(self._handle_kernel_restarted) |
@@ -112,7 +112,7 b' class ZMQTerminalIPythonApp(TerminalIPythonApp, IPythonConsoleApp):' | |||||
112 | IPythonConsoleApp.initialize(self) |
|
112 | IPythonConsoleApp.initialize(self) | |
113 | # relay sigint to kernel |
|
113 | # relay sigint to kernel | |
114 | signal.signal(signal.SIGINT, self.handle_sigint) |
|
114 | signal.signal(signal.SIGINT, self.handle_sigint) | |
115 |
self.shell = ZMQTerminalInteractiveShell.instance( |
|
115 | self.shell = ZMQTerminalInteractiveShell.instance(parent=self, | |
116 | display_banner=False, profile_dir=self.profile_dir, |
|
116 | display_banner=False, profile_dir=self.profile_dir, | |
117 | ipython_dir=self.ipython_dir, |
|
117 | ipython_dir=self.ipython_dir, | |
118 | manager=self.kernel_manager, |
|
118 | manager=self.kernel_manager, |
@@ -337,7 +337,7 b' class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):' | |||||
337 | # shell.display_banner should always be False for the terminal |
|
337 | # shell.display_banner should always be False for the terminal | |
338 | # based app, because we call shell.show_banner() by hand below |
|
338 | # based app, because we call shell.show_banner() by hand below | |
339 | # so the banner shows *before* all extension loading stuff. |
|
339 | # so the banner shows *before* all extension loading stuff. | |
340 |
self.shell = TerminalInteractiveShell.instance( |
|
340 | self.shell = TerminalInteractiveShell.instance(parent=self, | |
341 | display_banner=False, profile_dir=self.profile_dir, |
|
341 | display_banner=False, profile_dir=self.profile_dir, | |
342 | ipython_dir=self.ipython_dir) |
|
342 | ipython_dir=self.ipython_dir) | |
343 | self.shell.configurables.append(self) |
|
343 | self.shell.configurables.append(self) |
General Comments 0
You need to be logged in to leave comments.
Login now