7676from trinity .utils .profiling import (
7777 setup_cprofiler ,
7878)
79+ from trinity .utils .shutdown import (
80+ exit_on_signal
81+ )
7982from trinity .utils .version import (
8083 construct_trinity_client_identifier ,
8184)
@@ -260,6 +263,7 @@ def trinity_boot(args: Namespace,
260263 database_server_process ,
261264 networking_process ,
262265 plugin_manager ,
266+ main_endpoint ,
263267 event_bus
264268 )
265269 )
@@ -279,6 +283,7 @@ def trinity_boot(args: Namespace,
279283 database_server_process ,
280284 networking_process ,
281285 plugin_manager ,
286+ main_endpoint ,
282287 event_bus
283288 )
284289
@@ -287,6 +292,7 @@ def kill_trinity_gracefully(logger: logging.Logger,
287292 database_server_process : Any ,
288293 networking_process : Any ,
289294 plugin_manager : PluginManager ,
295+ main_endpoint : Endpoint ,
290296 event_bus : EventBus ,
291297 message : str = "Trinity shudown complete\n " ) -> None :
292298 # 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,
301307 # perform a non-gracefull shutdown if the process takes too long to terminate.
302308 logger .info ('Keyboard Interrupt: Stopping' )
303309 plugin_manager .shutdown ()
304- event_bus .shutdown ()
310+ main_endpoint .stop ()
311+ event_bus .stop ()
305312 kill_process_gracefully (database_server_process , logger )
306313 logger .info ('DB server process (pid=%d) terminated' , database_server_process .pid )
307314 # 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:
336343 raise
337344
338345
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-
354346@setup_cprofiler ('launch_node' )
355347@with_queued_logging
356348def launch_node (args : Namespace , chain_config : ChainConfig , endpoint : Endpoint ) -> None :
0 commit comments