1

I need to do some processing in the C backend during runtime. So what I want to do is, to define a C callback that'd get called each time there's a call to a non-existent python function.

For example:

// C code

PyObject* callback_func(PyObject* self, PyObject* args)
{

    // do stuff here
    return Py_BuildValue("");
}


# python code

print("Hello!")
call_xyz_func()
print("World!")

call_xyz_func is basically a non-existent python function. So it should call the C callback function and continue with the rest of the python code.

martineau
  • 119,623
  • 25
  • 170
  • 301
Insane
  • 31
  • 4
  • Nope. Python isn't extensible at that level. It will throw an exception. – Tim Roberts Apr 06 '22 at 22:12
  • That's a shame. I'll have to do it statically I guess – Insane Apr 07 '22 at 04:57
  • "Statically"?? I don't know what you mean. Using a name that doesn't exist results in a `NameError` exception. Doesn't matter whether it is a function or a variable. – Tim Roberts Apr 07 '22 at 06:13
  • Yea, thanks for the help. What I meant was I probably gonna create functions for each of my use cases instead of cramming them into a single one. Gonna be a bit tedious but should work I hope. – Insane Apr 07 '22 at 12:44

0 Answers0