##// END OF EJS Templates
Improve docstring for InProcessHBChannel
Thomas Kluyver -
Show More
@@ -1,95 +1,100 b''
1 """A kernel client for in-process kernels."""
1 """A kernel client for in-process kernels."""
2
2
3 # Copyright (c) IPython Development Team.
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
4 # Distributed under the terms of the Modified BSD License.
5
5
6 from IPython.kernel.channelsabc import (
6 from IPython.kernel.channelsabc import (
7 ShellChannelABC, IOPubChannelABC,
7 ShellChannelABC, IOPubChannelABC,
8 HBChannelABC, StdInChannelABC,
8 HBChannelABC, StdInChannelABC,
9 )
9 )
10
10
11 from .socket import DummySocket
11 from .socket import DummySocket
12
12
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Channel classes
14 # Channel classes
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16
17 class InProcessChannel(object):
17 class InProcessChannel(object):
18 """Base class for in-process channels."""
18 """Base class for in-process channels."""
19 proxy_methods = []
19 proxy_methods = []
20
20
21 def __init__(self, client=None):
21 def __init__(self, client=None):
22 super(InProcessChannel, self).__init__()
22 super(InProcessChannel, self).__init__()
23 self.client = client
23 self.client = client
24 self._is_alive = False
24 self._is_alive = False
25
25
26 def is_alive(self):
26 def is_alive(self):
27 return self._is_alive
27 return self._is_alive
28
28
29 def start(self):
29 def start(self):
30 self._is_alive = True
30 self._is_alive = True
31
31
32 def stop(self):
32 def stop(self):
33 self._is_alive = False
33 self._is_alive = False
34
34
35 def call_handlers(self, msg):
35 def call_handlers(self, msg):
36 """ This method is called in the main thread when a message arrives.
36 """ This method is called in the main thread when a message arrives.
37
37
38 Subclasses should override this method to handle incoming messages.
38 Subclasses should override this method to handle incoming messages.
39 """
39 """
40 raise NotImplementedError('call_handlers must be defined in a subclass.')
40 raise NotImplementedError('call_handlers must be defined in a subclass.')
41
41
42 def flush(self, timeout=1.0):
42 def flush(self, timeout=1.0):
43 pass
43 pass
44
44
45
45
46 def call_handlers_later(self, *args, **kwds):
46 def call_handlers_later(self, *args, **kwds):
47 """ Call the message handlers later.
47 """ Call the message handlers later.
48
48
49 The default implementation just calls the handlers immediately, but this
49 The default implementation just calls the handlers immediately, but this
50 method exists so that GUI toolkits can defer calling the handlers until
50 method exists so that GUI toolkits can defer calling the handlers until
51 after the event loop has run, as expected by GUI frontends.
51 after the event loop has run, as expected by GUI frontends.
52 """
52 """
53 self.call_handlers(*args, **kwds)
53 self.call_handlers(*args, **kwds)
54
54
55 def process_events(self):
55 def process_events(self):
56 """ Process any pending GUI events.
56 """ Process any pending GUI events.
57
57
58 This method will be never be called from a frontend without an event
58 This method will be never be called from a frontend without an event
59 loop (e.g., a terminal frontend).
59 loop (e.g., a terminal frontend).
60 """
60 """
61 raise NotImplementedError
61 raise NotImplementedError
62
62
63
63
64
64
65 class InProcessHBChannel(object):
65 class InProcessHBChannel(object):
66 """See `IPython.kernel.channels.HBChannel` for docstrings."""
66 """A dummy heartbeat channel interface for in-process kernels.
67
68 Normally we use the heartbeat to check that the kernel process is alive.
69 When the kernel is in-process, that doesn't make sense, but clients still
70 expect this interface.
71 """
67
72
68 time_to_dead = 3.0
73 time_to_dead = 3.0
69
74
70 def __init__(self, client=None):
75 def __init__(self, client=None):
71 super(InProcessHBChannel, self).__init__()
76 super(InProcessHBChannel, self).__init__()
72 self.client = client
77 self.client = client
73 self._is_alive = False
78 self._is_alive = False
74 self._pause = True
79 self._pause = True
75
80
76 def is_alive(self):
81 def is_alive(self):
77 return self._is_alive
82 return self._is_alive
78
83
79 def start(self):
84 def start(self):
80 self._is_alive = True
85 self._is_alive = True
81
86
82 def stop(self):
87 def stop(self):
83 self._is_alive = False
88 self._is_alive = False
84
89
85 def pause(self):
90 def pause(self):
86 self._pause = True
91 self._pause = True
87
92
88 def unpause(self):
93 def unpause(self):
89 self._pause = False
94 self._pause = False
90
95
91 def is_beating(self):
96 def is_beating(self):
92 return not self._pause
97 return not self._pause
93
98
94
99
95 HBChannelABC.register(InProcessHBChannel)
100 HBChannelABC.register(InProcessHBChannel)
General Comments 0
You need to be logged in to leave comments. Login now