Skip to content

Commit 4f1136f

Browse files
authored
log python thread trace (#2507)
1 parent 64249cb commit 4f1136f

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

packages/main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import logging
66
from helpermodules import logger
77
from helpermodules.utils import thread_handler
8+
import threading
9+
import sys
810

911
# als erstes logging initialisieren, damit auch ImportError geloggt werden
1012
logger.setup_logging()
@@ -73,6 +75,17 @@ def handler_with_control_interval():
7375

7476
log.info("# ***Start*** ")
7577
log.debug(f"Threads: {enumerate()}")
78+
for thread in threading.enumerate():
79+
logging.debug(f"Thread Name: {thread.name}")
80+
if hasattr(thread, "ident"):
81+
thread_id = thread.ident
82+
for tid, frame in sys._current_frames().items():
83+
if tid == thread_id:
84+
logging.debug(f" File: {frame.f_code.co_filename}, Line: {frame.f_lineno}, Function: {frame.f_code.co_name}")
85+
stack_trace = traceback.format_stack(frame)
86+
logging.debug(" Stack Trace:")
87+
for line in stack_trace:
88+
logging.debug(line.strip())
7689
Pub().pub("openWB/set/system/time", timecheck.create_timestamp())
7790
handler_with_control_interval()
7891
logger.write_logs_to_file("main")

0 commit comments

Comments
 (0)