[IronPython] Callback per statement

Markus Hajek markus.hajek at teamvienna.at
Tue Apr 17 08:54:32 CEST 2007


One more question: I want to use this callback to abort python execution in
certain cases. I'm currently thinking the best way to go about this would be
to throw an exception in the callback I hook up. 

About like:

 

public static class PythonCallback

{

                public static void Callback()

                {

                               If (pythonAbortionDesired)

                                               Throw new
PythonAbortionException();

                }

}

//.

try

{

engine.ExecuteFile("SomePythonFile.py");

}

catch (PythonAbortionException)

{

                // do whatever I wanna do when Python execution has aborted

}

 

What do you think of this? Is there any better alternative?

 

Many thanks again,

 

 

Markus Hajek

Team Vienna - Kazemi, Hajek & Pisarik OG

 

Von: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] Im Auftrag von Markus Hajek
Gesendet: Dienstag, 17. April 2007 08:38
An: 'Discussion of IronPython'
Betreff: Re: [IronPython] Callback per statement

 

Thanks a million, I'll start experimenting with that right away. Looks just
exactly like what I need, thanks again.

 

Cheers,

 

Markus Hajek

Team Vienna - Kazemi, Hajek & Pisarik OG

 

Von: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] Im Auftrag von Martin Maly
Gesendet: Montag, 16. April 2007 20:13
An: Discussion of IronPython
Betreff: Re: [IronPython] Callback per statement

 

It is not possible to do this without change to code generation at this
point. Essentially you could do something like this:

 

public class MyCallbackClass {

    public void MyCallback() {

        //

    }

}

 

And then emit call to this utility wherever you like:

cg.EmitCall(typeof(MyCallbackClass).GetMethod("MyCallback"))

 

You can then control the granularity at which you call this. Per statement,
or even per expression (I am a bit confused about your mention of operators
below, whether you want to do this for each expression, but it is certainly
possible as well).

 

For starters, what you could easily do to get feel for things would be to
modify SuiteStatement's Emit method (which only loops through enclosed
statements and emits each of them) and add the above "cg.EmitCall" for each
statement, run your repro, say:

 

X = 1

X = 2

X = 3

 

And put breakpoint in the "MyCallback", or better yet, run the repro:

 

Ipy.exe -X:SaveAssemblies x.py

 

And examine the x.exe we'll generate with ildasm or reflector. Then you can
add calls to your callbacks wherever desired.

 

Hope this helps

Martin

 

 

From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of Markus Hajek
Sent: Monday, April 16, 2007 3:37 AM
To: 'Discussion of IronPython'
Subject: [IronPython] Callback per statement

 

Hi,

is there a way to execute a callback whenever a Python statement is about to
be executed (or just has executed)? With Python statements, I mean method
calls, operators, assignments.

And if there's no such way, how would I have to go about changing code
generation to facilitate that?

Many thanks,

Markus Hajek

Team Vienna - Kazemi, Hajek & Pisarik OG

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20070417/7756669a/attachment.html>


More information about the Ironpython-users mailing list