Skip to content

Commit

Permalink
Ref #193 - Add additional logging in set resolve and traceback on SIG…
Browse files Browse the repository at this point in the history
…USR1
  • Loading branch information
mxsasha committed Feb 6, 2023
1 parent 38fade3 commit 23463fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions irrexplorer/api/collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def is_set(set_name: str) -> bool:
results = []

def traverse_tree(stub_name: str, depth: int = 0, path: Optional[List[str]] = None) -> None:
print(f"traverse_tree called with: stub_name={stub_name} depth={depth} path={path}")
if path is None:
path = []
if stub_name in path:
Expand All @@ -236,6 +237,7 @@ def traverse_tree(stub_name: str, depth: int = 0, path: Optional[List[str]] = No
if sub_member in resolved:
traverse_tree(sub_member, depth, path)

print("completed initial resolve loop, traversing tree")
traverse_tree(name)
results.sort(key=lambda item: (item.depth, item.name))

Expand Down
17 changes: 17 additions & 0 deletions irrexplorer/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import os
import signal
import sys
import threading
import traceback

import databases
from starlette.applications import Starlette
from starlette.middleware import Middleware
Expand All @@ -10,6 +16,7 @@


async def startup():
signal.signal(signal.SIGUSR1, sigusr1_handler)
app.state.database = databases.Database(DATABASE_URL, force_rollback=TESTING)
await app.state.database.connect()

Expand Down Expand Up @@ -48,3 +55,13 @@ async def shutdown():
on_startup=[startup],
on_shutdown=[shutdown],
)


def sigusr1_handler(signal, frame):
thread_names = {th.ident: th.name for th in threading.enumerate()}
code = [f"Traceback follows for all threads of process {os.getpid()}:"]
for thread_id, stack in sys._current_frames().items():
thread_name = thread_names.get(thread_id, "")
code.append(f"\n## Thread: {thread_name}({thread_id}) ##\n")
code += traceback.format_list(traceback.extract_stack(stack))
print("".join(code))

0 comments on commit 23463fb

Please sign in to comment.