Discussion:
[Python.NET] Cannot initialize OLE
Daniele Esposti
2008-12-01 13:53:29 UTC
Permalink
Hi all,

if I run my application (a wxPython frame with a wx.Activex Flash
component) with the python.exe in pythonnet folder its work like expected.
Instead, if I run my application with the standard Python interpreter,
with clr.pyd in DLLs folder and Python.Runtime.dll in the same
interpreter folder, I get a warnings says Cannot initialize OLE and the
ActiveX is locked.
I'm using Python 2.5.2 on a Windows XP SP3 machine, PythonNet
2.0-alpha2-clr2.0 compiled with VisualStudio Express 2008.

Have I missing something ? Only clr.pyd and Python.Runtime.dll are
needed or there are others resources to copy in Python interpreter folder ?

Thanks in advance
_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet
Brian Lloyd
2008-12-01 19:45:05 UTC
Permalink
This probably has to do with the threading model being auto-magically
set for you when the CLR is cranked up, absent any prior initialization.

The managed version of python.exe is able to set the threading model
(to MTA I believe) because it is a managed executable. When you import
clr via the standard python.exe, you are probably getting the default
model (STA). I could have those backwards - its been a while ;)

If you are using the win32com extensions, you might be able to import
those, set the threading model for the process, then import clr. Not
sure if that will work, but its worth a shot. I don't think there is
any way to change the threading model once it's set.

-Brian
Post by Daniele Esposti
Hi all,
if I run my application (a wxPython frame with a wx.Activex Flash
component) with the python.exe in pythonnet folder its work like expected.
Instead, if I run my application with the standard Python interpreter,
with clr.pyd in DLLs folder and Python.Runtime.dll in the same
interpreter folder, I get a warnings says Cannot initialize OLE and the
ActiveX is locked.
I'm using Python 2.5.2 on a Windows XP SP3 machine, PythonNet
2.0-alpha2-clr2.0 compiled with VisualStudio Express 2008.
Have I missing something ? Only clr.pyd and Python.Runtime.dll are
needed or there are others resources to copy in Python interpreter folder ?
Thanks in advance
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
--------------------------------
Brian Lloyd 540.845.2975

brian.lloyd-IsS0qfAs25g7rjH4CWuWblaTQe2KTcn/@public.gmane.org

_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet
Feihong Hsu
2008-12-01 21:13:46 UTC
Permalink
I believe Brian's assessment is correct. The easiest way to handle this is to use pywin32's pythoncom module to set the threading model. You can find a sample of how to do that here:

http://www.ironpython.info/index.php/Using_the_WebBrowser_Widget

In the sample, the WebBrowser widget (which uses ActiveX underneath) is embedded in a form. By invoking pythoncom.CoInitialize(), we set the threading model to STA which prevents the program from crashing when it initializes the form.

--- On Mon, 12/1/08, Brian Lloyd <brian.lloyd-IsS0qfAs25g7rjH4CWuWblaTQe2KTcn/@public.gmane.org> wrote:
From: Brian Lloyd <brian.lloyd-IsS0qfAs25g7rjH4CWuWblaTQe2KTcn/@public.gmane.org>
Subject: Re: [Python.NET] Cannot initialize OLE
To: "Daniele Esposti" <expo-***@public.gmane.org>, pythondotnet-+ZN9ApsXKcEdnm+***@public.gmane.org
Date: Monday, December 1, 2008, 1:45 PM

This probably has to do with the threading model being auto-magically
set for you when the CLR is cranked up, absent any prior initialization.

The managed version of python.exe is able to set the threading model
(to MTA I believe) because it is a managed executable. When you import
clr via the standard python.exe, you are probably getting the default
model (STA). I could have those backwards - its been a while ;)

If you are using the win32com extensions, you might be able to import
those, set the threading model for the process, then import clr. Not
sure if that will work, but its worth a shot. I don't think there is
any way to change the threading model once it's set.

-Brian
Post by Daniele Esposti
Hi all,
if I run my application (a wxPython frame with a wx.Activex Flash
component) with the python.exe in pythonnet folder its work like expected.
Instead, if I run my application with the standard Python interpreter,
with clr.pyd in DLLs folder and Python.Runtime.dll in the same
interpreter folder, I get a warnings says Cannot initialize OLE and the
ActiveX is locked.
I'm using Python 2.5.2 on a Windows XP SP3 machine, PythonNet
2.0-alpha2-clr2.0 compiled with VisualStudio Express 2008.
Have I missing something ? Only clr.pyd and Python.Runtime.dll are
needed or there are others resources to copy in Python interpreter folder ?
Thanks in advance
_________________________________________________
http://mail.python.org/mailman/listinfo/pythondotnet
--------------------------------
Brian Lloyd 540.845.2975

brian.lloyd-IsS0qfAs25g7rjH4CWuWblaTQe2KTcn/@public.gmane.org

_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet
Daniele Esposti
2008-12-03 01:18:37 UTC
Permalink
Post by Feihong Hsu
I believe Brian's assessment is correct. The easiest way to handle this
is to use pywin32's pythoncom module to set the threading model. You can
http://www.ironpython.info/index.php/Using_the_WebBrowser_Widget
In the sample, the WebBrowser widget (which uses ActiveX underneath) is
embedded in a form. By invoking pythoncom.CoInitialize(), we set the
threading model to STA which prevents the program from crashing when it
initializes the form.
Ok,

import pythoncom
pythoncom.CoInitialize()


and every it's working right.
Thank's to all
_________________________________________________
Python.NET mailing list - PythonDotNet-+ZN9ApsXKcEdnm+***@public.gmane.org
http://mail.python.org/mailman/listinfo/pythondotnet

Loading...