[IronPython] Sharing state between embedded PythonEngines
chris.stoy at redstorm.com
Wed Apr 11 22:00:37 CEST 2007
Well, a single console would be sufficient. I guess my real question is
what the best architecture is for having a console and executing
I imagine three ways to access IronPython:
1. an interactive console window (I already have this control working)
2. a script editing window (with possible debugger support)
3. executing a script file saved on disk
The first issue is the amount of setup that goes into creating a
PythonEngine instance set up to access objects exposed by my app. This
may not be a big deal, but seems wasteful to keep creating and
destroying these things.
The second issue is preserving state between script executions. Maybe
that is a bad idea in the first place and I should just make people
import their scripts when they want to use them.
What are other people doing?
From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
Sent: Wednesday, April 11, 2007 3:40 PM
To: Discussion of IronPython
Subject: Re: [IronPython] Sharing state between embedded PythonEngines
Chris Stoy wrote:
> Hi all,
> I'm working on embedding IronPython in a C# application and would like
> to have a single, global module where I expose my objects and run
> scripts, and have multiple views into that state.
That is certainly possible - but I'm not sure how easy it will be to
have multiple *consoles*.
Creating a custom control which receives input and displays the result
in a window. (Sharing a single context behind the scenes...)
Is using consoles as your view, central to your application ?
> For example, I want to have one (or more) IronPython console views
> that provide an interactive prompt that the user can type in and
> execute code. If I enter a function/variable in one of the consoles,
> then it is also available in the others. (ie, I enter "x=1" in console
> A and in console B I can say "print x" and see "1" output.) I also
> want to execute much larger, non-interactive scripts that a user can
> write and, again, this state is shared across all my IronPython views.
> So, am I just thinking about this wrong? How are people embedding
> IronPython in their apps? It seems strange (and inefficient) to have
> to create a new PythonEngine and add all the references and expose
> globals every time I want to execute script. Is there a way to share
> some of this state? Can this be done using EngineModules?
> Any thoughts would be appreciated.
> users mailing list
> users at lists.ironpython.com
users mailing list
users at lists.ironpython.com
More information about the Ironpython-users