Show More
@@ -1,52 +1,52 b'' | |||||
1 | """ Defines a KernelClient that provides signals and slots. |
|
1 | """ Defines a KernelClient that provides signals and slots. | |
2 | """ |
|
2 | """ | |
3 |
|
3 | |||
4 | from IPython.external.qt import QtCore |
|
4 | from IPython.external.qt import QtCore | |
5 |
|
5 | |||
6 | # Local imports |
|
6 | # Local imports | |
7 | from IPython.utils.traitlets import Bool, Instance |
|
7 | from IPython.utils.traitlets import Bool, Instance | |
8 |
|
8 | |||
9 | from IPython.kernel import KernelManager |
|
9 | from IPython.kernel import KernelManager | |
10 | from IPython.kernel.restarter import KernelRestarter |
|
10 | from IPython.kernel.restarter import KernelRestarter | |
11 |
|
11 | |||
12 | from .kernel_mixins import QtKernelManagerMixin, QtKernelRestarterMixin |
|
12 | from .kernel_mixins import QtKernelManagerMixin, QtKernelRestarterMixin | |
13 |
|
13 | |||
14 |
|
14 | |||
15 | class QtKernelRestarter(KernelRestarter, QtKernelRestarterMixin): |
|
15 | class QtKernelRestarter(KernelRestarter, QtKernelRestarterMixin): | |
16 |
|
16 | |||
17 | def start(self): |
|
17 | def start(self): | |
18 | if self._timer is None: |
|
18 | if self._timer is None: | |
19 | self._timer = QtCore.QTimer() |
|
19 | self._timer = QtCore.QTimer() | |
20 | self._timer.timeout.connect(self.poll) |
|
20 | self._timer.timeout.connect(self.poll) | |
21 | self._timer.start(self.time_to_dead * 1000) |
|
21 | self._timer.start(self.time_to_dead * 1000) | |
22 |
|
22 | |||
23 | def stop(self): |
|
23 | def stop(self): | |
24 | self._timer.stop() |
|
24 | self._timer.stop() | |
25 |
|
25 | |||
26 | def poll(self): |
|
26 | def poll(self): | |
27 | super(QtKernelRestarter, self).poll() |
|
27 | super(QtKernelRestarter, self).poll() | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | class QtKernelManager(KernelManager, QtKernelManagerMixin): |
|
30 | class QtKernelManager(KernelManager, QtKernelManagerMixin): | |
31 | """A KernelManager with Qt signals for restart""" |
|
31 | """A KernelManager with Qt signals for restart""" | |
32 |
|
32 | |||
33 | autorestart = Bool(True, config=True) |
|
33 | autorestart = Bool(True, config=True) | |
34 |
|
34 | |||
35 | def start_restarter(self): |
|
35 | def start_restarter(self): | |
36 | if self.autorestart and self.has_kernel: |
|
36 | if self.autorestart and self.has_kernel: | |
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 | config=self.config, |
|
40 | config=self.config, | |
41 | log=self.log, |
|
41 | log=self.log, | |
42 | ) |
|
42 | ) | |
43 |
self._restarter. |
|
43 | self._restarter.add_callback(self._handle_kernel_restarted) | |
44 | self._restarter.start() |
|
44 | self._restarter.start() | |
45 |
|
45 | |||
46 | def stop_restarter(self): |
|
46 | def stop_restarter(self): | |
47 | if self.autorestart: |
|
47 | if self.autorestart: | |
48 | if self._restarter is not None: |
|
48 | if self._restarter is not None: | |
49 | self._restarter.stop() |
|
49 | self._restarter.stop() | |
50 |
|
50 | |||
51 | def _handle_kernel_restarted(self): |
|
51 | def _handle_kernel_restarted(self): | |
52 | self.kernel_restarted.emit() |
|
52 | self.kernel_restarted.emit() |
General Comments 0
You need to be logged in to leave comments.
Login now