1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-14 14:22:10 +03:00

companion: Create CAPI worker thread on startup

Confirmed to also *not* block shutdown currently
This commit is contained in:
Athanasius 2021-08-16 14:07:29 +01:00
parent bfaf66d873
commit c5af0a3397
No known key found for this signature in database
GPG Key ID: AE3E527847057C7D

View File

@ -14,6 +14,7 @@ import json
import numbers import numbers
import os import os
import random import random
import threading
import time import time
import urllib.parse import urllib.parse
import webbrowser import webbrowser
@ -476,6 +477,15 @@ class Session(object):
self.auth: Optional[Auth] = None self.auth: Optional[Auth] = None
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...')
self.capi_query_thread = threading.Thread(
target=self.capi_query_worker,
daemon=True,
name='CAPI worker'
)
self.capi_query_thread.start()
logger.info('Done')
###################################################################### ######################################################################
# Frontier Authorization # Frontier Authorization
###################################################################### ######################################################################
@ -579,6 +589,18 @@ class Session(object):
###################################################################### ######################################################################
# CAPI queries # CAPI queries
###################################################################### ######################################################################
def capi_query_enqueue(self, endpoint: str) -> None:
"""Request the worker thread perform a given endpoint query."""
...
def capi_query_worker(self, ):
"""Worker thread that performs actual CAPI queries."""
logger.info('CAPI worker thread starting')
while True:
time.sleep(1)
logger.info('CAPI worker thread DONE')
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}"')