Hi All,<div><br></div><div>I am seeing weird problems with embedding PythonNET/Python 2.6 in a C#, using 4.0 runtime application built with VS2010 on Windows XP SP3. </div><div><br></div><div>Design outline</div><div>--------------------</div>
<div>For every script I execute the following sequence on a separate thread (does not seem to matter the same or different one every time) to avoid blocking GUI:</div><div><br></div><div><div>PythonEngine.Initialize();</div>
<div><br></div><div>&lt;the following block executed several times with startup scripts and then the actual user script&gt;</div><div>IntPtr pythonLock = PythonEngine.AcquireLock();</div><div>PythonEngine.RunSimpleString(source);</div>
<div>PythonEngine.ReleaseLock(pythonLock);</div><div><br></div><div>PythonEngine.Shutdown();</div></div><div><br></div><div>I use the RunSimpleString() as the RunString() didn&#39;t work for me (always returns NULL and does not execute the code, suggestions welcome!).</div>
<div><br></div><div>Problem description</div><div>-----------------------------</div><div>Running simple scripts like &#39;print &quot;whatever&quot;&#39; goes well. I can run scripts multiple (&gt;10) times without any side-effects. Problems start when importing certain modules (like ctypes, numpy), or accessing collections of .NET objects returned by the .NET API. For example, the following scripts will fail executing SECOND time. Whenever I call the script AGAIN I get AccessViolationException or even ExecutionEngineException (with debugger attached of course) in the Shutdown() call. </div>
<div><br></div><div>Example 1</div><div>---------------</div><div>import ctypes</div><div><br></div><div>Exampe 2</div><div>--------------</div><div>import clr</div><div>clr.AddReference(&quot;System.Drawing&quot;)</div><div>
import System.Drawing</div><div>bmp = System.Drawing.Bitmap(&quot;c:\\image.bmp&quot;)</div><div><br></div><div>I should be doing something completely wrong, but I just cannot see it... </div><div><br></div><div>Please help!</div>
<div><div><br></div></div><div>-- <br>oleksii<br>
</div>