@@ -192,13 +192,14 @@ def main(cls):
192192 # Run the event loop
193193 try :
194194 asyncio .run (cls ._main (config_filepath , config_file , args ))
195- except asyncio . CancelledError :
196- pass
195+ except KeyboardInterrupt :
196+ asyncio . run ( cls . shutdown_all ( signal . SIGINT , loop = cls . loop ))
197197
198198 @classmethod
199199 async def _main (cls , config_filepath , config_file , args = None ):
200200 """Parse command line arguments, run event loop."""
201201 loop = asyncio .get_running_loop ()
202+ cls .loop = loop
202203 if sys .platform .startswith ("win" ):
203204 signals = ()
204205 else :
@@ -208,27 +209,24 @@ async def _main(cls, config_filepath, config_file, args=None):
208209 s , lambda s = s : asyncio .create_task (cls .shutdown_all (s , loop ))
209210 )
210211
211- try :
212+ cls .__servers = set ()
213+ for section in config_file :
214+ if section == "shared-settings" :
215+ continue
216+ try :
217+ config = cls ._parse_config (config_file , section , args )
218+ except ValueError as e :
219+ logger .error (str (e ))
220+ continue
221+ logger .debug (f"Starting { section } with { config } " )
222+ await cls ._start_daemon (section , config , config_filepath )
223+
224+ while cls .__servers :
225+ awaiting = cls .__servers
212226 cls .__servers = set ()
213- for section in config_file :
214- if section == "shared-settings" :
215- continue
216- try :
217- config = cls ._parse_config (config_file , section , args )
218- except ValueError as e :
219- logger .error (str (e ))
220- continue
221- logger .debug (f"Starting { section } with { config } " )
222- await cls ._start_daemon (section , config , config_filepath )
223-
224- while cls .__servers :
225- awaiting = cls .__servers
226- cls .__servers = set ()
227- await asyncio .wait (awaiting )
228- await asyncio .sleep (1 )
229- loop .stop ()
230- except KeyboardInterrupt : # handle windows ctrl+c
231- await cls .shutdown_all (signal .SIGINT , loop )
227+ await asyncio .wait (awaiting )
228+ await asyncio .sleep (1 )
229+ loop .stop ()
232230
233231 @classmethod
234232 async def _start_daemon (cls , name , config , config_filepath ):
0 commit comments