76
76
from trinity .utils .profiling import (
77
77
setup_cprofiler ,
78
78
)
79
+ from trinity .utils .shutdown import (
80
+ exit_on_signal
81
+ )
79
82
from trinity .utils .version import (
80
83
construct_trinity_client_identifier ,
81
84
)
@@ -260,6 +263,7 @@ def trinity_boot(args: Namespace,
260
263
database_server_process ,
261
264
networking_process ,
262
265
plugin_manager ,
266
+ main_endpoint ,
263
267
event_bus
264
268
)
265
269
)
@@ -279,6 +283,7 @@ def trinity_boot(args: Namespace,
279
283
database_server_process ,
280
284
networking_process ,
281
285
plugin_manager ,
286
+ main_endpoint ,
282
287
event_bus
283
288
)
284
289
@@ -287,6 +292,7 @@ def kill_trinity_gracefully(logger: logging.Logger,
287
292
database_server_process : Any ,
288
293
networking_process : Any ,
289
294
plugin_manager : PluginManager ,
295
+ main_endpoint : Endpoint ,
290
296
event_bus : EventBus ,
291
297
message : str = "Trinity shudown complete\n " ) -> None :
292
298
# When a user hits Ctrl+C in the terminal, the SIGINT is sent to all processes in the
@@ -301,7 +307,8 @@ def kill_trinity_gracefully(logger: logging.Logger,
301
307
# perform a non-gracefull shutdown if the process takes too long to terminate.
302
308
logger .info ('Keyboard Interrupt: Stopping' )
303
309
plugin_manager .shutdown ()
304
- event_bus .shutdown ()
310
+ main_endpoint .stop ()
311
+ event_bus .stop ()
305
312
kill_process_gracefully (database_server_process , logger )
306
313
logger .info ('DB server process (pid=%d) terminated' , database_server_process .pid )
307
314
# XXX: This short sleep here seems to avoid us hitting a deadlock when attempting to
@@ -336,21 +343,6 @@ def _sigint_handler(*args: Any) -> None:
336
343
raise
337
344
338
345
339
- async def exit_on_signal (service_to_exit : BaseService ) -> None :
340
- loop = service_to_exit .get_event_loop ()
341
- sigint_received = asyncio .Event ()
342
- for sig in [signal .SIGINT , signal .SIGTERM ]:
343
- # TODO also support Windows
344
- loop .add_signal_handler (sig , sigint_received .set )
345
-
346
- await sigint_received .wait ()
347
- try :
348
- await service_to_exit .cancel ()
349
- service_to_exit ._executor .shutdown (wait = True )
350
- finally :
351
- loop .stop ()
352
-
353
-
354
346
@setup_cprofiler ('launch_node' )
355
347
@with_queued_logging
356
348
def launch_node (args : Namespace , chain_config : ChainConfig , endpoint : Endpoint ) -> None :
0 commit comments