views:

40

answers:

0

Hi all,

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.