[IronPython] Foolproof IP Embedding

Alex alex at glumol.com
Fri Jul 9 17:20:55 CEST 2010

2010/7/8 Michael Foord <fuzzyman at voidspace.org.uk>

>  On 08/07/2010 22:34, Alex wrote:
> Hello
> In my WPF application, I want to have an "expert mode" that lets the
> end-user write inline python code targetting one specific control (a
> sheetmusic). I embed IronPython and when the user code throws an exception I
> catch it and display it but there are a few foolproof problems:
>  1) If the user write some bad code in a function and binds it to one of
> the control event, it will crash the whole app. Of course I can recommand my
> users to always wrap event handlers into a try catch block (or ask to use a
> decorator that do it) but it's not really foolproof. I want to make it
> impossible to crash the whole app with user code. Perhaps native events
> mecanism is a bit too low-level to be foolproof?
> Catch and report exceptions.
hi Mickael

if the user write this code :


def foo():
print 2/0

button.Click = foo


the script will execute with no exception, only when the button is clicked,
an exception is raised, how should I handle it ?

>  2) If the user code makes  an infinite loop it will hang the whole app. I
> want to have a "panic button" to stop the script (and even restart the
> python engine if necessary). I suppose I have to run user code in a worker
> thread but then the user have to use Invoke mecanisms each time he touchs an
> UI object? Is there an elegant pattern that deals with this concerns?
> Execute the user code on a background thread. Provide a means for actions
> to be invoked on the gui thread (wrapped in exception handling) if
> necessary. Provide a button to abort the thread if it goes on too long.

My only concern is that the users shouldn't have to think about it. Maybe I
should only let them access UI elements through non-UI proxy objects, but
it's a great limitation.

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

More information about the Ironpython-users mailing list