Mercurial > libervia-backend
comparison sat/core/launcher.py @ 3416:d7cfb031e41f
core (launcher): exit code can now specified
Exit code can now be specified by setting the `_exitCode` variable in
`twisted.application.app` module.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 14 Nov 2020 21:19:40 +0100 |
parents | 751d8fa45ced |
children | be6d91572633 |
comparison
equal
deleted
inserted
replaced
3415:814e118d9ef3 | 3416:d7cfb031e41f |
---|---|
21 import sys | 21 import sys |
22 import os | 22 import os |
23 import argparse | 23 import argparse |
24 from pathlib import Path | 24 from pathlib import Path |
25 from configparser import ConfigParser | 25 from configparser import ConfigParser |
26 from os.path import expanduser, join | |
27 from twisted.application import app | 26 from twisted.application import app |
28 from twisted.python import usage | 27 from twisted.python import usage |
29 from sat.core.constants import Const as C | 28 from sat.core.constants import Const as C |
30 | 29 |
31 | 30 |
98 if state == 'init': | 97 if state == 'init': |
99 state = 'waiting' | 98 state = 'waiting' |
100 print(f"Still waiting for {self.APP_NAME} to be terminated…") | 99 print(f"Still waiting for {self.APP_NAME} to be terminated…") |
101 elif state == 'waiting' and now - kill_started > 10: | 100 elif state == 'waiting' and now - kill_started > 10: |
102 state == 'killing' | 101 state == 'killing' |
103 print(f"Waiting for too long, we kill the process") | 102 print("Waiting for too long, we kill the process") |
104 os.kill(pid, signal.SIGKILL) | 103 os.kill(pid, signal.SIGKILL) |
105 sys.exit(1) | 104 sys.exit(1) |
106 | 105 |
107 sys.exit(0) | 106 sys.exit(0) |
108 | 107 |
231 else: | 230 else: |
232 runner = app_runner(server_options) | 231 runner = app_runner(server_options) |
233 runner.run() | 232 runner.run() |
234 if runner._exitSignal is not None: | 233 if runner._exitSignal is not None: |
235 app._exitWithSignal(runner._exitSignal) | 234 app._exitWithSignal(runner._exitSignal) |
235 try: | |
236 sys.exit(app._exitCode) | |
237 except AttributeError: | |
238 pass | |
236 | 239 |
237 @classmethod | 240 @classmethod |
238 def run(cls): | 241 def run(cls): |
239 args = cls().parse_args() | 242 args = cls().parse_args() |
240 args.cmd(args) | 243 args.cmd(args) |