Search code examples
c#web-servicesironpythonopenrasta

RESTful Webservice with embedded IronPython: engine & scope questions


I have a RESTful C# web service (using Open Rasta) that I want to run IronPython scripts that talk to a CouchDB.

One thing I could use some clarification on is: How often do I need a new instance of the python engine and the scope? one each per application? per session? per request?

I currently have a static engine at the application level along with a dictionary of compiled scripts; then, per request, I create a new scope and execute the code within that scope...

Is that correct? thread safe? and as performant as it could be?

EDIT: regarding the bounty Please also answer the question I posed in reply to Jeff: Will a static instance of the engine cause sequential requests from different clients to wait in line to execute? if so I will probably need everything on a per-request basis.


Solution

  • A ScriptRuntime/ScriptEngine per application and a Scope per request is exactly how it should be done. Runtimes/Engine are thread-safe and Scopes are not.