We're doing something similar with IPY 1.1 and it works so far. Basically, we use IP for "content templating" and each request executes a script with certain variables.<br><br>I don;t know if it is really thread safe, but we've had no issues.<br>
<br>hth,<br> Miha.<br><br><div class="gmail_quote">2008/12/30 Michael Foord <span dir="ltr"><<a href="mailto:fuzzyman@voidspace.org.uk">fuzzyman@voidspace.org.uk</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello Josh,<br>
<br>
Sorry for the delayed reply - life is hectic at the moment and I'm still copy editing IronPython in Action.<br>
<br>
I've copied your email to the IronPython list as I don't know whether the CreateScope and other methods of the ScriptEngine are thread safe. My instinct would be to say no, but on the other hand the DLR has to handle running multi-threaded code so maybe...<br>
<br>
Michael Foord<br>
<br>
<a href="mailto:greenbergjosh@hotmail.com" target="_blank">greenbergjosh@hotmail.com</a> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Some one has sent you a message via your contact form. They filled in the<br>
following values :<br>
<br>
comment = I read your article on IronPython and I was hoping you might have an answer to the following question.<br>
<br>
I would like to embed IronPython in a web application. I would like to initialize the engine and runtime in the Application_Start() method and store an instance of the ScriptEngine in the Application object. Then, any time I need to run some python I intend to call the ScriptEngine::CreateScope() method and use it to get a new scope in which to execute my code. Is this approach thread safe? I will have only one instance of the ScriptEngine shared by many threads. Each thread will call CreateScope whenever it chooses.<br>
<br>
<br>
It will look something like:<br>
<br>
<br>
protected void Application_Start(object sender, EventArgs e)<br>
<br>
{<br>
<br>
ScriptRuntime truntime = ScriptRuntime.Create();<br>
<br>
ScriptEngine teng = truntime.GetEngine("py");<br>
<br>
this.Application.Add(“PythonEngine†, teng);<br>
<br>
}<br>
<br>
<br>
Then, in some web page or dll called by a web page I would do<br>
<br>
<br>
..<br>
<br>
ScriptEngine se = (ScriptEngine)Application[“PythonEngine†];<br>
<br>
ScriptScope ss = se.CreateScope();<br>
<br>
ScriptSource src = se.CreateScriptSourceFromString(“y=24†, SourceCodeKind.Statements);<br>
<br>
CompiledCode cc = src.Compile();<br>
<br>
cc.Execute(scope);<br>
<br>
...<br>
<br>
<br>
Is this going to work or will I run into threading problems? In other words, is the ScriptEngine thread-safe? Will it serialize all of my cc.Execute() calls? Any other insight into its behavior in this regard would be appreciated.<br>
<br>
<br>
Many Thanks,<br>
<br>
Josh<br>
<br>
name = Josh<br>
email = <a href="mailto:greenbergjosh@hotmail.com" target="_blank">greenbergjosh@hotmail.com</a><br>
subject = Embedding IronPython<br>
<br>
</blockquote>
<br>
<br>
-- <br>
<a href="http://www.ironpythoninaction.com/" target="_blank">http://www.ironpythoninaction.com/</a><br>
<a href="http://www.voidspace.org.uk/blog" target="_blank">http://www.voidspace.org.uk/blog</a><br>
<br>
<br>
<br>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br></blockquote></div><br>