@@ -115,18 +115,18 @@ def configure_parser(self, arg_parser: ArgumentParser, subparser: _SubParsersAct
115
115
"""
116
116
pass
117
117
118
- def boot (self ) -> None :
118
+ def start (self ) -> None :
119
119
"""
120
120
Prepare the plugin to get started and eventually cause ``start`` to get called.
121
121
"""
122
122
self .running = True
123
- self .start ()
123
+ self ._start ()
124
124
self .event_bus .broadcast (
125
125
PluginStartedEvent (type (self ))
126
126
)
127
127
self .logger .info ("Plugin started: %s" , self .name )
128
128
129
- def start (self ) -> None :
129
+ def _start (self ) -> None :
130
130
"""
131
131
The ``start`` method is called only once when the plugin is started. In the case
132
132
of an `BaseIsolatedPlugin` this method will be launched in a separate process.
@@ -138,18 +138,40 @@ class BaseSyncStopPlugin(BasePlugin):
138
138
"""
139
139
A ``BaseSyncStopPlugin`` unwinds synchronoulsy, hence blocks until shut down is done.
140
140
"""
141
- def stop (self ) -> None :
141
+ def _stop (self ) -> None :
142
+ """
143
+ Stop the plugin. Should be overwritten by subclasses.
144
+ """
142
145
pass
143
146
147
+ def stop (self ) -> None :
148
+ """
149
+ Stop the plugin by delegating to
150
+ :meth:`~trinity.extensibility.plugin.BaseSyncStopPlugin._stop`
151
+ """
152
+ self ._stop ()
153
+ self .running = False
154
+
144
155
145
156
class BaseAsyncStopPlugin (BasePlugin ):
146
157
"""
147
158
A ``BaseAsyncStopPlugin`` unwinds asynchronoulsy, hence needs to be awaited.
148
159
"""
149
160
150
- async def stop (self ) -> None :
161
+ async def _stop (self ) -> None :
162
+ """
163
+ Asynchronously stop the plugin. Should be overwritten by subclasses.
164
+ """
151
165
pass
152
166
167
+ async def stop (self ) -> None :
168
+ """
169
+ Asynchronously stop the plugin by delegating to
170
+ :meth:`~trinity.extensibility.plugin.BaseAsyncStopPlugin._stop`
171
+ """
172
+ await self ._stop ()
173
+ self .running = False
174
+
153
175
154
176
class BaseMainProcessPlugin (BasePlugin ):
155
177
"""
@@ -170,7 +192,7 @@ class BaseIsolatedPlugin(BaseSyncStopPlugin):
170
192
171
193
_process : Process = None
172
194
173
- def boot (self ) -> None :
195
+ def start (self ) -> None :
174
196
"""
175
197
Prepare the plugin to get started and eventually cause ``start`` to get called.
176
198
"""
@@ -190,9 +212,9 @@ def _prepare_start(self) -> None:
190
212
self .event_bus .broadcast (
191
213
PluginStartedEvent (type (self ))
192
214
)
193
- self .start ()
215
+ self ._start ()
194
216
195
- def stop (self ) -> None :
217
+ def _stop (self ) -> None :
196
218
self .context .event_bus .stop ()
197
219
kill_process_gracefully (self ._process , self .logger )
198
220
@@ -212,7 +234,7 @@ def configure_parser(self, arg_parser: ArgumentParser, subparser: _SubParsersAct
212
234
def handle_event (self , activation_event : BaseEvent ) -> None :
213
235
self .logger .info ("Debug plugin: handle_event called: %s" , activation_event )
214
236
215
- def start (self ) -> None :
237
+ def _start (self ) -> None :
216
238
self .logger .info ("Debug plugin: start called" )
217
239
asyncio .ensure_future (self .count_forever ())
218
240
@@ -223,5 +245,5 @@ async def count_forever(self) -> None:
223
245
i += 1
224
246
await asyncio .sleep (1 )
225
247
226
- async def stop (self ) -> None :
248
+ async def _stop (self ) -> None :
227
249
self .logger .info ("Debug plugin: stop called" )
0 commit comments