Embedding: Is it possible to limit number of virtual instructions executed?

juliangrendell at gmail.com juliangrendell at gmail.com
Sat Nov 1 07:41:05 CET 2008


Hi experts-

I have a potential use case of embedding Python where it must co-
operate with the host c/c++ application in a single thread.  That is,
the c code and python interpreter need to cooperate and time share, or
yield to each other.

The main loop would need to do something like:

check for events
for events with c handlers:
    process in c
for events with python handlers:
    add to queue
if have time:
    python_continue_execution(number of vm instructions)

The goal is to be able to set some limit on the amount of time in the
interpreter in each loop, and not rely on the python side code.  (I
realise this will not be absolute, especially if the python code calls
c extensions, but it will be more straight forward for the users.)

Does anyone have any suggestions for how this could be achieved?

Thanks in advance,

Julian



More information about the Python-list mailing list