Skip to content

Commit ebdcfd4

Browse files
Improved logging - printing a caller script name upon start
1 parent 2045cfa commit ebdcfd4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

sagemaker_ssh_helper/env.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
from typing import List
34

45

56
def sm_get_node_rank():
@@ -15,3 +16,15 @@ def sm_get_node_rank():
1516
rc = json.load(json_file)
1617

1718
return int(rc["hosts"].index(rc["current_host"]))
19+
20+
21+
def get_caller_script_name(trace_back=1):
22+
import inspect
23+
from inspect import FrameInfo
24+
from pathlib import Path
25+
26+
stack: List[FrameInfo] = inspect.stack()
27+
if len(stack) < 2:
28+
raise AssertionError("Cannot fetch stack trace")
29+
30+
return Path(stack[trace_back].filename).name

0 commit comments

Comments
 (0)