469,923 Members | 1,777 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

Interrupting execution of PyRun_SimpleScript()

Hi,

Im am using PyRun_SimpleString() inside a BCB 5.0 GUI app
on win32.

All works fine.

The PyRun_SimpleStript() runs a piece of python
code which calls often a callback function to
refresh my gui App so my Form still can react
to user input.

Now, I would like to implement a possibility
to interrupt the execution.

For this I have a button called "stop", and when
the user executes it, I generate an exeption by
calling:
PyRun_SimpleString("raise KeyboardInterrupt\n").

I see in the window where I redirected stderr and stdout
the exception, but the original code (a for loop)
still continues to run.

Does there somebody have some idea (in the Python FAQ
i didnT find anything)

Thanks

Anton
Jul 19 '05 #1
1 1489
A few days ago stephan wrote:
Im am using PyRun_SimpleString() inside a BCB 5.0 GUI app
on win32.
Never used it so can only offer a suggestion.
For this I have a button called "stop", and when
the user executes it, I generate an exeption by
calling:
PyRun_SimpleString("raise KeyboardInterrupt\n").


The fact that your GUI can call SimpleString implies
to me that Python is running with multiple threads.
The string is executed in a different thread from your
other thread. The exception isn't being called from
the right thread. Instead it's caught by the top-level
exception handler for the GUI, which reports the error.

Is it possible to put an explicit "check this variable
and if it's true then abort" in your time-intensive code?

Andrew
da***@dalkescientific.com

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jenny Zhang | last post: by
75 posts views Thread by Beni | last post: by
2 posts views Thread by Ina Schmitz | last post: by
1 post views Thread by John Savage | last post: by
8 posts views Thread by andreas | last post: by
4 posts views Thread by jehugaleahsa | last post: by
6 posts views Thread by geoffbache | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.