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.

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.

Michael

This questions are more about .NET and patterns than IronPython, but I figured some of you have already thought about it in your IP experience. Thanks for any advices!

Alex





_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your 
employer, to release me from all obligations and waivers arising from any and all 
NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, 
confidentiality, non-disclosure, non-compete and acceptable use policies ("BOGUS 
AGREEMENTS") that I have entered into with your employer, its partners, licensors, 
agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. 
You further represent that you have the authority to release me from any BOGUS AGREEMENTS 
on behalf of your employer.


_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to