Python C API - Termination (and continued later)

1) I would like to use profiling functions in the Python C API to catch the python interpreter when it returns from certain functions.

2) I would like to pause the python interpreter, send back the execution of the function that the interpreter called in my C ++ program, and finally return the python interpreter to execution by running it in the line of code after it stopped. I would like to support both global and local networks between times when execution belongs to python.

Part 1 I have finished. Part 2 is my question. I do not know what to save so that I can return to execution or how to return to execution, taking into account the saved data.

From what I could get from python API documents, I would have to save part of the executable frame, but I did not find anything. Some additional questions ... What does PyFrameObject actually contain? The python API unexpectedly never explains this.

+3
source share
1 answer

If I understand your problem, you have a C ++ program that calls in python. When python finishes executing the function, you want to pause the interpreter and choose where the C ++ code stopped. Some time later, your C ++ program should return to python, and the python interpreter will pick up where it left off.

, . , :

[ top of stack ]
[ some interpreter frames ]
[ some c++ frames ] 

, ++. , , , . (. http://en.wikipedia.org/wiki/Setjmp.h), . API .

. , ++ ( 1), ++ 2 python.

( ++) 1, 2 (, , . https://computing.llnl.gov/tutorials/pthreads/). 1, . 2 ( ) 1 . , 2 ( 2, 1 ). . , .

+2

All Articles