controller: Improve shutdown handling
This commit is contained in:
parent
244a340764
commit
f501dc046e
@ -1,6 +1,7 @@
|
|||||||
import configparser
|
import configparser
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import signal
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import infi.systray
|
import infi.systray
|
||||||
@ -51,7 +52,7 @@ def main():
|
|||||||
conf.read(CONFIG_FILE)
|
conf.read(CONFIG_FILE)
|
||||||
with open(CONFIG_FILE, 'w') as f:
|
with open(CONFIG_FILE, 'w') as f:
|
||||||
conf.write(f)
|
conf.write(f)
|
||||||
conf.getboolean('general', 'dummy_impl')
|
use_dummy_impl = conf.getboolean('general', 'dummy_impl')
|
||||||
|
|
||||||
log_level = parse_log_level(conf['general']['log_level'])
|
log_level = parse_log_level(conf['general']['log_level'])
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
@ -71,10 +72,10 @@ def main():
|
|||||||
val_sm = valconomy.ValconomyStateMachine(conf['valorant']['player_uuid'], val_handler)
|
val_sm = valconomy.ValconomyStateMachine(conf['valorant']['player_uuid'], val_handler)
|
||||||
|
|
||||||
val_client = valconomy.ValorantLocalClient(val_sm.handle_presence)
|
val_client = valconomy.ValorantLocalClient(val_sm.handle_presence)
|
||||||
def do_quit(tray: infi.systray.SysTrayIcon):
|
def do_quit(*args):
|
||||||
log.info('Shutting down')
|
log.info('Shutting down')
|
||||||
val_client.stop()
|
val_client.stop()
|
||||||
if use_dummy_impl:
|
if not use_dummy_impl:
|
||||||
val_handler.stop()
|
val_handler.stop()
|
||||||
|
|
||||||
with infi.systray.SysTrayIcon(
|
with infi.systray.SysTrayIcon(
|
||||||
@ -82,7 +83,9 @@ def main():
|
|||||||
menu_options=(
|
menu_options=(
|
||||||
('Open data directory', None, do_open_datadir),
|
('Open data directory', None, do_open_datadir),
|
||||||
)) as tray:
|
)) as tray:
|
||||||
val_client.run()
|
signal.signal(signal.SIGINT, do_quit)
|
||||||
|
signal.signal(signal.SIGTERM, do_quit)
|
||||||
|
val_client.run()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import base64
|
import base64
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
import errno
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
@ -287,7 +286,7 @@ class HIDValconomyHandler(ValconomyHandler):
|
|||||||
|
|
||||||
while not self._dev_ready():
|
while not self._dev_ready():
|
||||||
if not self.running:
|
if not self.running:
|
||||||
break
|
return
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -298,6 +297,8 @@ class HIDValconomyHandler(ValconomyHandler):
|
|||||||
def run(self):
|
def run(self):
|
||||||
while self.running:
|
while self.running:
|
||||||
while self.queue.empty():
|
while self.queue.empty():
|
||||||
|
if not self.running:
|
||||||
|
return
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
self.service()
|
self.service()
|
||||||
@ -308,7 +309,9 @@ class HIDValconomyHandler(ValconomyHandler):
|
|||||||
self._thread.start()
|
self._thread.start()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
assert self._thread is not None and self.running
|
if self._thread is None or not self.running:
|
||||||
|
return
|
||||||
|
self.running = False
|
||||||
self._thread.join()
|
self._thread.join()
|
||||||
|
|
||||||
def none(self):
|
def none(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user