Reputation: 17
Using the python script engine set up in C# using IronPython, is there a way to retrieve the current executing function from the python code?
E. g. in my code, the setup python script engine is stored in variable pse
. Is there a call similar to pse.GetVariables()
that returns the current executing python function?
I would like to be able to pull this information so I could use it in a check within a test, for example.
Upvotes: 0
Views: 229
Reputation: 15217
You can use the trace functionality for that. Set a trace callback that will be called for each line of the executing script. From that callback, you can get the function name that is currently executing.
pse.SetTrace(IronPythonTraceCallbaback);
And the callback definition:
static TracebackDelegate IronPythonTraceBack(TraceBackFrame frame, string result, object payload)
{
if (frame != null && frame.f_code != null)
{
// Here you can access the executing function information
FunctionCode functionCode = frame.f_code;
string functionName = frame.f_code.co_name;
}
return IronPythonTraceBack;
}
Upvotes: 1