views:

70

answers:

1

Howdy,

I'm trying to extend one of my WebApps using IronPython, unfortunately the code below runs pretty slowly:

        var engine = Python.CreateEngine();
        SourceCodeKind st = SourceCodeKind.Statements;
        string source = "print 'Hello World'";
        var script = engine.CreateScriptSourceFromString(source, st);
        var scope = engine.CreateScope();
        script.Execute(scope);

I'm assuming that the creation of the Python Engine is taking most of the time, as even an interpreted language such as Python should run relatively fast.

So, assuming my assumptions are correct; can I store the Python Engine somewhere to save the expense of having to create it every time? Or is there a better way to do this?

Anthony

+1  A: 

If access to the engine is thread safe, you can simply store it in a static instance variable somewhere.

If access is not thread safe, you should synchronize access to it, possibly pooling the instances to reduce lock contention.

mookid8000