mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-03 09:01:13 +03:00
plugins/inara: Close down logging & Remove unused this.queue.
* The new_worker/NewThis doesn't currently have a mechanism to ask the new_worker to exit. It's relying on being a daemon thread and dying once all non-daemon (i.e. main) threads have exited.
This commit is contained in:
parent
8aac704fa1
commit
9b09d8bd07
@ -5,10 +5,8 @@ import json
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
# For new impl
|
|
||||||
from collections import OrderedDict, defaultdict, deque
|
from collections import OrderedDict, defaultdict, deque
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from queue import Queue
|
|
||||||
from threading import Lock, Thread
|
from threading import Lock, Thread
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING, Any, AnyStr, Callable, Deque, Dict, List, Mapping, MutableMapping, NamedTuple, Optional
|
TYPE_CHECKING, Any, AnyStr, Callable, Deque, Dict, List, Mapping, MutableMapping, NamedTuple, Optional
|
||||||
@ -39,7 +37,6 @@ CREDIT_RATIO = 1.05 # Update credits if they change by 5% over the course of a
|
|||||||
|
|
||||||
this: Any = sys.modules[__name__] # For holding module globals
|
this: Any = sys.modules[__name__] # For holding module globals
|
||||||
this.session = timeout_session.new_session()
|
this.session = timeout_session.new_session()
|
||||||
this.queue = Queue() # Items to be sent to Inara by worker thread
|
|
||||||
this.lastlocation = None # eventData from the last Commander's Flight Log event
|
this.lastlocation = None # eventData from the last Commander's Flight Log event
|
||||||
this.lastship = None # eventData from the last addCommanderShip or setCommanderShip event
|
this.lastship = None # eventData from the last addCommanderShip or setCommanderShip event
|
||||||
|
|
||||||
@ -164,10 +161,16 @@ def station_url(system_name: str, station_name: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def plugin_start3(plugin_dir: str) -> str:
|
def plugin_start3(plugin_dir: str) -> str:
|
||||||
"""Plugin start Hook."""
|
"""
|
||||||
|
Start this plugin.
|
||||||
|
|
||||||
|
Start the worker thread to handle sending to Inara API.
|
||||||
|
"""
|
||||||
|
logger.debug('Starting worker thread...')
|
||||||
this.thread = Thread(target=new_worker, name='Inara worker')
|
this.thread = Thread(target=new_worker, name='Inara worker')
|
||||||
this.thread.daemon = True
|
this.thread.daemon = True
|
||||||
this.thread.start()
|
this.thread.start()
|
||||||
|
logger.debug('Done.')
|
||||||
|
|
||||||
return 'Inara'
|
return 'Inara'
|
||||||
|
|
||||||
@ -182,13 +185,15 @@ def plugin_app(parent: tk.Tk) -> None:
|
|||||||
|
|
||||||
def plugin_stop() -> None:
|
def plugin_stop() -> None:
|
||||||
"""Plugin shutdown hook."""
|
"""Plugin shutdown hook."""
|
||||||
# Signal thread to close and wait for it
|
logger.debug('We have no way to ask new_worker to stop, but...')
|
||||||
this.queue.put(None)
|
# The Newthis/new_worker doesn't have a method to ask the new_worker to
|
||||||
# this.thread.join()
|
# stop. We're relying on it being a daemon thread and thus exiting when
|
||||||
# this.thread = None
|
# there are no non-daemon (i.e. main) threads running.
|
||||||
|
|
||||||
this.timer_run = False
|
this.timer_run = False
|
||||||
|
|
||||||
|
logger.debug('Done.')
|
||||||
|
|
||||||
|
|
||||||
def plugin_prefs(parent: tk.Tk, cmdr: str, is_beta: bool) -> tk.Frame:
|
def plugin_prefs(parent: tk.Tk, cmdr: str, is_beta: bool) -> tk.Frame:
|
||||||
"""Plugin Preferences UI hook."""
|
"""Plugin Preferences UI hook."""
|
||||||
@ -1189,12 +1194,14 @@ def new_add_event(
|
|||||||
|
|
||||||
def new_worker():
|
def new_worker():
|
||||||
"""
|
"""
|
||||||
Queue worker.
|
Handle sending events to the Inara API.
|
||||||
|
|
||||||
Will only ever send one message per WORKER_WAIT_TIME, regardless of status.
|
Will only ever send one message per WORKER_WAIT_TIME, regardless of status.
|
||||||
"""
|
"""
|
||||||
|
logger.debug('Starting...')
|
||||||
while True:
|
while True:
|
||||||
events = get_events()
|
events = get_events()
|
||||||
|
|
||||||
for creds, event_list in events.items():
|
for creds, event_list in events.items():
|
||||||
if not event_list:
|
if not event_list:
|
||||||
continue
|
continue
|
||||||
@ -1216,6 +1223,8 @@ def new_worker():
|
|||||||
|
|
||||||
time.sleep(WORKER_WAIT_TIME)
|
time.sleep(WORKER_WAIT_TIME)
|
||||||
|
|
||||||
|
logger.debug('Done.')
|
||||||
|
|
||||||
|
|
||||||
def get_events(clear: bool = True) -> Dict[Credentials, List[Event]]:
|
def get_events(clear: bool = True) -> Dict[Credentials, List[Event]]:
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user