提交 c63a32b0 编写于 作者: W wenkai

log exception raised by new thread to help debugging

上级 aeac0039
...@@ -759,17 +759,17 @@ class DataManager: ...@@ -759,17 +759,17 @@ class DataManager:
self._reload_interval = reload_interval self._reload_interval = reload_interval
self._max_threads_count = max_threads_count self._max_threads_count = max_threads_count
thread = threading.Thread(target=self._reload_data, thread = threading.Thread(target=self._reload_data_in_thread,
name='start_load_data_thread') name='start_load_data_thread')
thread.daemon = True thread.daemon = True
thread.start() thread.start()
def _reload_data(self): def _reload_data_in_thread(self):
"""This function periodically loads the data.""" """This function periodically loads the data."""
# Let gunicorn load other modules first. # Let gunicorn load other modules first.
time.sleep(1) time.sleep(1)
while True: while True:
self._load_data() self._load_data_in_thread()
if not self._reload_interval: if not self._reload_interval:
break break
...@@ -782,11 +782,19 @@ class DataManager: ...@@ -782,11 +782,19 @@ class DataManager:
This function needs to be used after `start_load_data` function. This function needs to be used after `start_load_data` function.
""" """
logger.debug("start to reload data") logger.debug("start to reload data")
thread = threading.Thread(target=self._load_data, thread = threading.Thread(target=self._load_data_in_thread,
name='reload_data_thread') name='reload_data_thread')
thread.daemon = False thread.daemon = False
thread.start() thread.start()
def _load_data_in_thread(self):
"""Log (but not swallow) exceptions in thread to help debugging."""
try:
self._load_data()
except Exception as exc:
logger.exception(exc)
raise
def _load_data(self): def _load_data(self):
"""This function will load data once and ignore it if the status is loading.""" """This function will load data once and ignore it if the status is loading."""
logger.info("Start to load data, reload interval: %r.", self._reload_interval) logger.info("Start to load data, reload interval: %r.", self._reload_interval)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册