Skip to content

Commit 1e0eac6

Browse files
committed
using our own abspath function
os.path.abspath might fail during shutdown see https://bugs.python.org/msg315588
1 parent d7cf1c7 commit 1e0eac6

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

scorep/_instrumenters/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import os
1+
from scorep._bindings import abspath
22

33

44
def get_module_name(frame):
55
"""Get the name of the module the given frame resides in"""
6-
modulename = frame.f_globals.get('__name__', None)
6+
modulename = frame.f_globals.get("__name__", None)
77
if modulename is None:
88
# this is a NUMPY special situation, see NEP-18, and Score-P Issue
99
# issues #63
@@ -18,7 +18,7 @@ def get_file_name(frame):
1818
"""Get the full path to the file the given frame resides in"""
1919
file_name = frame.f_code.co_filename
2020
if file_name is not None:
21-
full_file_name = os.path.abspath(file_name)
21+
full_file_name = abspath(file_name)
2222
else:
2323
full_file_name = "None"
2424
return full_file_name

src/methods.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "methods.hpp"
22
#include "scorepy/events.hpp"
3+
#include "scorepy/pathUtils.hpp"
34
#include <Python.h>
45
#include <cstdint>
56
#include <scorep/SCOREP_User_Functions.h>
@@ -180,6 +181,16 @@ extern "C"
180181
return PyUnicode_FromString(SCOREP_GetExperimentDirName());
181182
}
182183

184+
static PyObject* abspath(PyObject* self, PyObject* args)
185+
{
186+
const char* path;
187+
188+
if (!PyArg_ParseTuple(args, "s", &path))
189+
return NULL;
190+
191+
return PyUnicode_FromString(scorepy::abspath(path).c_str());
192+
}
193+
183194
static PyMethodDef ScorePMethods[] = {
184195
{ "region_begin", region_begin, METH_VARARGS, "enter a region." },
185196
{ "region_end", region_end, METH_VARARGS, "exit a region." },
@@ -194,6 +205,7 @@ extern "C"
194205
{ "parameter_string", parameter_string, METH_VARARGS, "User parameter string." },
195206
{ "get_experiment_dir_name", get_experiment_dir_name, METH_VARARGS,
196207
"Get the Score-P experiment dir." },
208+
{ "abspath", abspath, METH_VARARGS, "Estimates the absolute Path." },
197209
{ NULL, NULL, 0, NULL } /* Sentinel */
198210
};
199211
}

0 commit comments

Comments
 (0)