Embedded Python - Blocking operations in time module

I'm developing my own Python code interpreter using the Python C API, as described in the Python documentation. I've taken a look on the Python source code and I tried to follow the same steps that are carried out in the standard interpreter when executing a py file. These steps (sequence of C API function calls) are basically:

PyRun_AnyFileExFlags()
  PyRun_SimpleFileExFlags()
    PyRun_FileExFlags()
        PyArena_New()
        PyParser_ASTFromFile()
        run_mod()
            PyAST_Compile()
            PyEval_EvalCode()
                PyEval_EvalCodeEx()
                    PyThreadState_GET()
                    PyFrame_New()
                    PyEval_EvalFrameEx()

The only difference in my code is that I do manually the AST compilation, frame creation, etc. and then I call PyEval_EvalFrame.

With this, I am able to execute an arbitrary .py file with my program, as if it were the normal Python interpreter. My problem comes when the code that my program is executing makes use of the time module: all time module operations get blocked in the GIL! For example, if the Python code calls time.sleep(1), this call is blocked and never gets executed.

Obviously I am doing something wrong that blocks the GIL (and therefore blocks the time module) but I dont know how to correct it. The last statement in my code where I have control is in PyEval_EvalFrameEx, and from that point on, everything runs "as in regular Python interpreter", I think.

Anybody had a similar problem? What am I doing wrong, so that I block the time module? Hope somebody can help me...

Thanks for your time. Best regards,

R.

Answers


You need to provide more detail.

  • How does your interpreter's behavior differ from the standard interpreter?
  • If you just want to run arbitrary source files, why are you not calling one of the higher level interfaces, like PyRun_SimpleFile? Did your code call Py_Initialize?

Need Your Help

How to use Zend DB to add value to existing value in table

php zend-framework zend-db

I would like to do the follow query in Zend DB style. Basically i want to add 1000 to the value in my table where id = 1.