[IronPython] Multi threaded engine

Dino Viehland dinov at microsoft.com
Mon Jun 7 17:53:22 CEST 2010

Jeff wrote:
> On Mon, Jun 7, 2010 at 7:14 AM, Christos Pavlides <ncichris at gmail.com>
> wrote:
> > I am thinking that it could be better if the ScriptEngine and
> CompiledCode
> > are thread safe, and if I create one static engine an one static
> > CompliledCode then this will minimize the compile time since the
> rules will
> > have to be compiled one time and then reused for all threads.
> My understanding is that this is the case - for NWSGI I use a single
> engine (per AppDomain, but that's not important) and each script is
> compiled once into a CompiledCode object. On each request it gets a
> new scope from the engine, finds the CompiledCode for the requested
> script, and executes it in that scope. IIS can have a lot of worker
> threads handling requests at any time, so it's basically the same
> scenario you have. As long as you don't reuse scopes (and they're very
> cheap to create) you should be just fine.

This is correct and is definitely the recommended way to do this.  The
only reason to separate it out into separate ScriptEngine instances is
if you want isolation between the script engines themselves so that
one piece of user code cannot see another piece of user code.

More information about the Ironpython-users mailing list