mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-18 09:57:40 +03:00
companion: Implement, and use, asking CAPI thread to close down
This commit is contained in:
parent
c5af0a3397
commit
9661d770cb
@ -1577,6 +1577,10 @@ class AppWindow(object):
|
|||||||
logger.info('Unregistering hotkey manager...')
|
logger.info('Unregistering hotkey manager...')
|
||||||
hotkeymgr.unregister()
|
hotkeymgr.unregister()
|
||||||
|
|
||||||
|
# Now the CAPI query thread
|
||||||
|
logger.info('Closing CAPI query thread...')
|
||||||
|
companion.session.capi_query_close_worker()
|
||||||
|
|
||||||
# Now the main programmatic input methods
|
# Now the main programmatic input methods
|
||||||
logger.info('Closing dashboard...')
|
logger.info('Closing dashboard...')
|
||||||
dashboard.close()
|
dashboard.close()
|
||||||
|
13
companion.py
13
companion.py
@ -21,6 +21,7 @@ import webbrowser
|
|||||||
from builtins import object, range, str
|
from builtins import object, range, str
|
||||||
from email.utils import parsedate
|
from email.utils import parsedate
|
||||||
from os.path import join
|
from os.path import join
|
||||||
|
from queue import Queue
|
||||||
from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Optional, OrderedDict, TypeVar, Union
|
from typing import TYPE_CHECKING, Any, Dict, List, Mapping, Optional, OrderedDict, TypeVar, Union
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@ -478,6 +479,7 @@ class Session(object):
|
|||||||
self.retrying = False # Avoid infinite loop when successful auth / unsuccessful query
|
self.retrying = False # Avoid infinite loop when successful auth / unsuccessful query
|
||||||
|
|
||||||
logger.info('Starting CAPI queries thread...')
|
logger.info('Starting CAPI queries thread...')
|
||||||
|
self.capi_query_queue: Queue = Queue()
|
||||||
self.capi_query_thread = threading.Thread(
|
self.capi_query_thread = threading.Thread(
|
||||||
target=self.capi_query_worker,
|
target=self.capi_query_worker,
|
||||||
daemon=True,
|
daemon=True,
|
||||||
@ -596,11 +598,22 @@ class Session(object):
|
|||||||
def capi_query_worker(self, ):
|
def capi_query_worker(self, ):
|
||||||
"""Worker thread that performs actual CAPI queries."""
|
"""Worker thread that performs actual CAPI queries."""
|
||||||
logger.info('CAPI worker thread starting')
|
logger.info('CAPI worker thread starting')
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
query: Optional[str] = self.capi_query_queue.get()
|
||||||
|
if not query:
|
||||||
|
logger.info('Empty queue message, exiting...')
|
||||||
|
break
|
||||||
|
|
||||||
|
logger.trace_if('capi.worker', f'Processing query: {query}')
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
logger.info('CAPI worker thread DONE')
|
logger.info('CAPI worker thread DONE')
|
||||||
|
|
||||||
|
def capi_query_close_worker(self) -> None:
|
||||||
|
"""Ask the CAPI query thread to finish."""
|
||||||
|
self.capi_query_queue.put(None)
|
||||||
|
|
||||||
def query(self, endpoint: str) -> CAPIData: # noqa: CCR001, C901
|
def query(self, endpoint: str) -> CAPIData: # noqa: CCR001, C901
|
||||||
"""Perform a query against the specified CAPI endpoint."""
|
"""Perform a query against the specified CAPI endpoint."""
|
||||||
logger.trace_if('capi.query', f'Performing query for endpoint "{endpoint}"')
|
logger.trace_if('capi.query', f'Performing query for endpoint "{endpoint}"')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user