[Python.NET] python 2.5

Christian Heimes lists at cheimes.de
Tue Oct 16 19:03:57 CEST 2007

Paul Harter wrote:
> To use python.net with it is fine as long as the initial import of clr
> takes place early on in the main thread. Otherwise it doesn't work on
> multi-processor machines. I don't know why.

import clr should always be the first thing you do in an app. "import
clr" loads and initializes the Python.Runtime assembly. During the
initialization Python's __import__ hook is replaced with a custom hook
for the CLR import magic. You can get in all kinds of trouble if you
replace __import__ in a thread while another threads tries to import an
assembly. Our you can suffer from an import dead lock. It's a race

In an embedded .NET or C/C++ app you shouldn't use clr. It's better to
import the Python.Runtime assembly and call its PythonEngine::InitExt()
static method. The sample implementation in
contains a working example and some helpful notes from me. I run into a
problem with threads, too.


More information about the PythonDotNet mailing list