Skip to content

Commit b34d514

Browse files
committed
Confirm Device ID API Thread works
1 parent 77a47ba commit b34d514

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/libinspector/device_list_page.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,25 @@
55
import common
66
import logging
77
import functools
8-
import threading
98
import os
109
import requests
1110

12-
1311
logger = logging.getLogger("client")
1412

13+
1514
def show():
1615
"""
1716
Creating a page that shows what devices have been discovered so far
1817
"""
1918
toast_obj = st.toast('Discovering devices...')
2019
show_list(toast_obj)
2120

22-
@functools.lru_cache(maxsize=1)
23-
def start_inspector_once():
24-
"""Initialize the Inspector core only once."""
25-
with st.spinner("Starting API Thread..."):
26-
threading.Thread(
27-
target=worker_thread,
28-
daemon=True,
29-
)
30-
3121

3222
def worker_thread():
3323
"""
3424
A worker thread to periodically clear the cache of call_predict_api.
3525
"""
26+
logger.info("[Device ID API] Starting worker thread to periodically call the API for each device.")
3627
while True:
3728
time.sleep(15)
3829
db_conn, rwlock = libinspector.global_state.db_conn_and_lock
@@ -46,6 +37,7 @@ def worker_thread():
4637
with rwlock:
4738
for device_dict in db_conn.execute(sql):
4839
device_list.append(dict(device_dict))
40+
logger.info("[Device ID API] 15 seconds passed, will start calling API for each device if needed.")
4941

5042
# Getting inputs and calling API
5143
for device_dict in device_list:

src/libinspector/page_manager.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import functools
1111
import common
1212
import libinspector.core
13+
import threading
1314

1415

1516
def get_page(title, material_icon, show_page_func):
@@ -74,6 +75,12 @@ def start_inspector_once():
7475
common.config_set("suppress_warning", False)
7576
common.config_set("labeling_in_progress", False)
7677
libinspector.core.start_threads()
78+
api_thread = threading.Thread(
79+
name="Device API Thread",
80+
target=device_list_page.worker_thread,
81+
daemon=True,
82+
)
83+
api_thread.start()
7784

7885

7986
device_list_page_obj = get_page(

0 commit comments

Comments
 (0)