Show More
@@ -0,0 +1,52 b'' | |||||
|
1 | """ Defines a KernelClient that provides signals and slots. | |||
|
2 | """ | |||
|
3 | ||||
|
4 | from IPython.external.qt import QtCore | |||
|
5 | ||||
|
6 | # Local imports | |||
|
7 | from IPython.utils.traitlets import Bool, Instance | |||
|
8 | ||||
|
9 | from IPython.kernel import KernelManager | |||
|
10 | from IPython.kernel.restarter import KernelRestarter | |||
|
11 | ||||
|
12 | from .kernel_mixins import QtKernelManagerMixin, QtKernelRestarterMixin | |||
|
13 | ||||
|
14 | ||||
|
15 | class QtKernelRestarter(KernelRestarter, QtKernelRestarterMixin): | |||
|
16 | ||||
|
17 | def start(self): | |||
|
18 | if self._timer is None: | |||
|
19 | self._timer = QtCore.QTimer() | |||
|
20 | self._timer.timeout.connect(self.poll) | |||
|
21 | self._timer.start(self.time_to_dead * 1000) | |||
|
22 | ||||
|
23 | def stop(self): | |||
|
24 | self._timer.stop() | |||
|
25 | ||||
|
26 | def poll(self): | |||
|
27 | super(QtKernelRestarter, self).poll() | |||
|
28 | ||||
|
29 | ||||
|
30 | class QtKernelManager(KernelManager, QtKernelManagerMixin): | |||
|
31 | """A KernelManager with Qt signals for restart""" | |||
|
32 | ||||
|
33 | autorestart = Bool(True, config=True) | |||
|
34 | ||||
|
35 | def start_restarter(self): | |||
|
36 | if self.autorestart and self.has_kernel: | |||
|
37 | if self._restarter is None: | |||
|
38 | self._restarter = QtKernelRestarter( | |||
|
39 | kernel_manager=self, | |||
|
40 | config=self.config, | |||
|
41 | log=self.log, | |||
|
42 | ) | |||
|
43 | self._restarter.register_callback(self._handle_kernel_restarted) | |||
|
44 | self._restarter.start() | |||
|
45 | ||||
|
46 | def stop_restarter(self): | |||
|
47 | if self.autorestart: | |||
|
48 | if self._restarter is not None: | |||
|
49 | self._restarter.stop() | |||
|
50 | ||||
|
51 | def _handle_kernel_restarted(self): | |||
|
52 | self.kernel_restarted.emit() |
@@ -168,6 +168,21 b' class QtHBChannelMixin(ChannelQObject):' | |||||
168 | self.kernel_died.emit(since_last_heartbeat) |
|
168 | self.kernel_died.emit(since_last_heartbeat) | |
169 |
|
169 | |||
170 |
|
170 | |||
|
171 | class QtKernelRestarterMixin(HasTraits, SuperQObject): | |||
|
172 | ||||
|
173 | __metaclass__ = MetaQObjectHasTraits | |||
|
174 | _timer = None | |||
|
175 | ||||
|
176 | ||||
|
177 | class QtKernelManagerMixin(HasTraits, SuperQObject): | |||
|
178 | """ A KernelClient that provides signals and slots. | |||
|
179 | """ | |||
|
180 | ||||
|
181 | __metaclass__ = MetaQObjectHasTraits | |||
|
182 | ||||
|
183 | kernel_restarted = QtCore.Signal() | |||
|
184 | ||||
|
185 | ||||
171 | class QtKernelClientMixin(HasTraits, SuperQObject): |
|
186 | class QtKernelClientMixin(HasTraits, SuperQObject): | |
172 | """ A KernelClient that provides signals and slots. |
|
187 | """ A KernelClient that provides signals and slots. | |
173 | """ |
|
188 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now