Interpreter hook during evaluation

W

WilliamKF

Hello,

I would like access to a hook inside Python that would allow me to
register a C++ function to be called periodically during the
evaluation of a Python script.

Does any such thing exist today in Python? I poked around but didn't
find anything.

I want to do this for interrupt handling. I'd like to be able to
interrupt long running Python commands. I have a hook which would
throw a C++ exception if an interrupt is detected. I would then catch
this at the place where my application which embeds Python invokes a
Python command. My hook is written to be very fast, so calling it
every Python instruction would not be that bad in terms of
performance.

I'd like to avoid changing the existing Python implementation, which
is why I'm looking for a hook. Otherwise, a user would not be able to
substitute in their own Python implementation if they so desire
instead of taking the default on our app uses.

Thanks for the ideas.

-William
 
T

ThunderBug

I would like access to a hook inside Python that would allow me to
register a C++ function to be called periodically during the
evaluation of a Python script.

... so calling it
every Python instruction would not be that bad in terms of
performance.

I too could make good use of such a hook.
 
D

Diez B. Roggisch

Hello,

I would like access to a hook inside Python that would allow me to
register a C++ function to be called periodically during the
evaluation of a Python script.

Does any such thing exist today in Python? I poked around but didn't
find anything.

I want to do this for interrupt handling. I'd like to be able to
interrupt long running Python commands. I have a hook which would
throw a C++ exception if an interrupt is detected. I would then catch
this at the place where my application which embeds Python invokes a
Python command. My hook is written to be very fast, so calling it
every Python instruction would not be that bad in terms of
performance.

I'd like to avoid changing the existing Python implementation, which
is why I'm looking for a hook. Otherwise, a user would not be able to
substitute in their own Python implementation if they so desire
instead of taking the default on our app uses.

trace.

http://www.dalkescientific.com/writings/diary/archive/2005/04/20/tracing_python_code.html


Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top