From sebastian at yuca-lab.de Thu Jan 3 11:46:17 2008 From: sebastian at yuca-lab.de (Sebastian Stang) Date: Thu, 3 Jan 2008 11:46:17 +0100 Subject: [Python.NET] dotnet, threading and py2exe Message-ID: <60442E57-FFAC-4E6B-8AC6-7B244463B8DD@yuca-lab.de> Dear pythoneers, i want to deliver my program, which runs perfectly 'uncompiled', as an exe file to customers. The problem: i have to use an activeX component in a windows-form, and com-components can only be created in single-thread apartments. But when i use py2exe to compile it, the application is run in a multi- threaded-apartment (System.Threading.Thread.CurrentThread.GetApartmentState() is MTA). I tried some workarounds, e.g. create the form in an STA-thread or create the activex in an STA like this: thread_is_ready = False axBrowser = None def create_browser_thread(*args): global thread_is_ready global axBrowser print System.Threading.Thread.CurrentThread.GetApartmentState() axBrowser = AxSHDocVw.AxWebBrowser() thread_is_ready = True #and the initialization function in my main form class: def InitializeComponent(self): global thread_is_ready global axBrowser job = System.Threading.ThreadStart(create_browser_thread) thread = System.Threading.Thread(job) thread.SetApartmentState(System.Threading.ApartmentState.STA) thread.Start() while not thread_is_ready: pass self.Controls.Add(axBrowser) This all worked fine when run with python.exe from command-line. However, compiled with py2exe, the initialization function ends without exceptions, but the form is not shown and the program hangs. Telling the form to shop does not help either. Did anyone experience similar problems? best regards, Pablo From brian.lloyd at revolutionhealth.com Thu Jan 3 15:44:14 2008 From: brian.lloyd at revolutionhealth.com (Brian Lloyd) Date: Thu, 03 Jan 2008 09:44:14 -0500 Subject: [Python.NET] dotnet, threading and py2exe In-Reply-To: <60442E57-FFAC-4E6B-8AC6-7B244463B8DD@yuca-lab.de> Message-ID: Hi Sebastian - when you talk about it 'running perfectly with the normal python.exe', I assume you mean the one that comes with python.net. That exe is actually written in C# and explicitly sets the apartment mode to STA. I suspect the problem is that py2exe will create its own form of exe which won't do that, so you'll get the default threading model (MTA). It might be possible for your script to set the main thread to STA, if it is the very first thing your program does. You may want to refer to the docs on that -- I remember it was kind of complicated and hard to get it set from python code, but don't recall all of the details. -Brian On 1/3/08 5:46 AM, "Sebastian Stang" wrote: > Dear pythoneers, > i want to deliver my program, which runs perfectly 'uncompiled', as an > exe file to customers. > > The problem: i have to use an activeX component in a windows-form, and > com-components can only be created in single-thread apartments. > But when i use py2exe to compile it, the application is run in a multi- > threaded-apartment > (System.Threading.Thread.CurrentThread.GetApartmentState() is MTA). > > I tried some workarounds, e.g. create the form in an STA-thread or > create the activex in an STA like this: > > thread_is_ready = False > axBrowser = None > def create_browser_thread(*args): > global thread_is_ready > global axBrowser > print System.Threading.Thread.CurrentThread.GetApartmentState() > axBrowser = AxSHDocVw.AxWebBrowser() > thread_is_ready = True > > #and the initialization function in my main form class: > def InitializeComponent(self): > global thread_is_ready > global axBrowser > job = System.Threading.ThreadStart(create_browser_thread) > thread = System.Threading.Thread(job) > thread.SetApartmentState(System.Threading.ApartmentState.STA) > thread.Start() > while not thread_is_ready: > pass > self.Controls.Add(axBrowser) > > This all worked fine when run with python.exe from command-line. > However, compiled with py2exe, the initialization function ends > without exceptions, but the form is not shown and the program hangs. > Telling the form to shop does not help either. > > Did anyone experience similar problems? > > best regards, > Pablo > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet -------------------------- Brian Lloyd brian.lloyd at revolutionhealth.com From mkozyarchuk at funddevelopmentservices.com Thu Jan 3 16:55:22 2008 From: mkozyarchuk at funddevelopmentservices.com (Maksim Kozyarchuk) Date: Thu, 3 Jan 2008 10:55:22 -0500 Subject: [Python.NET] dotnet, threading and py2exe In-Reply-To: Message-ID: We found that the following code as the first line of your python file puts you into the STA. import pythoncom pythoncom.CoInitialize() Maksim On 1/3/08 9:44 AM, "Brian Lloyd" wrote: > Hi Sebastian - when you talk about it 'running perfectly with > the normal python.exe', I assume you mean the one that comes > with python.net. > > That exe is actually written in C# and explicitly sets the > apartment mode to STA. > > I suspect the problem is that py2exe will create its own form > of exe which won't do that, so you'll get the default threading > model (MTA). > > It might be possible for your script to set the main thread to > STA, if it is the very first thing your program does. You may > want to refer to the docs on that -- I remember it was kind of > complicated and hard to get it set from python code, but don't > recall all of the details. > > -Brian > > > On 1/3/08 5:46 AM, "Sebastian Stang" wrote: > >> > Dear pythoneers, >> > i want to deliver my program, which runs perfectly 'uncompiled', as an >> > exe file to customers. >> > >> > The problem: i have to use an activeX component in a windows-form, and >> > com-components can only be created in single-thread apartments. >> > But when i use py2exe to compile it, the application is run in a multi- >> > threaded-apartment >> > (System.Threading.Thread.CurrentThread.GetApartmentState() is MTA). >> > >> > I tried some workarounds, e.g. create the form in an STA-thread or >> > create the activex in an STA like this: >> > >> > thread_is_ready = False >> > axBrowser = None >> > def create_browser_thread(*args): >> > global thread_is_ready >> > global axBrowser >> > print System.Threading.Thread.CurrentThread.GetApartmentState() >> > axBrowser = AxSHDocVw.AxWebBrowser() >> > thread_is_ready = True >> > >> > #and the initialization function in my main form class: >> > def InitializeComponent(self): >> > global thread_is_ready >> > global axBrowser >> > job = System.Threading.ThreadStart(create_browser_thread) >> > thread = System.Threading.Thread(job) >> > thread.SetApartmentState(System.Threading.ApartmentState.STA) >> > thread.Start() >> > while not thread_is_ready: >> > pass >> > self.Controls.Add(axBrowser) >> > >> > This all worked fine when run with python.exe from command-line. >> > However, compiled with py2exe, the initialization function ends >> > without exceptions, but the form is not shown and the program hangs. >> > Telling the form to shop does not help either. >> > >> > Did anyone experience similar problems? >> > >> > best regards, >> > Pablo >> > _________________________________________________ >> > Python.NET mailing list - PythonDotNet at python.org >> > http://mail.python.org/mailman/listinfo/pythondotnet > > -------------------------- > Brian Lloyd > > brian.lloyd at revolutionhealth.com > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20080103/5b8aface/attachment.htm From brian.lloyd at revolutionhealth.com Thu Jan 3 17:19:06 2008 From: brian.lloyd at revolutionhealth.com (Brian Lloyd) Date: Thu, 03 Jan 2008 11:19:06 -0500 Subject: [Python.NET] dotnet, threading and py2exe In-Reply-To: Message-ID: wow, python.net, pythoncom and py2exe. Just need to find a way to import IronPython and use something from that too... ;) -Brian On 1/3/08 10:55 AM, "Maksim Kozyarchuk" wrote: > We found that the following code as the first line of your python file puts > you into the STA. > > import pythoncom > pythoncom.CoInitialize() > > Maksim > > On 1/3/08 9:44 AM, "Brian Lloyd" wrote: > >> Hi Sebastian - when you talk about it 'running perfectly with >> the normal python.exe', I assume you mean the one that comes >> with python.net. >> >> That exe is actually written in C# and explicitly sets the >> apartment mode to STA. >> >> I suspect the problem is that py2exe will create its own form >> of exe which won't do that, so you'll get the default threading >> model (MTA). >> >> It might be possible for your script to set the main thread to >> STA, if it is the very first thing your program does. You may >> want to refer to the docs on that -- I remember it was kind of >> complicated and hard to get it set from python code, but don't >> recall all of the details. >> >> -Brian >> >> >> On 1/3/08 5:46 AM, "Sebastian Stang" wrote: >> >>> > Dear pythoneers, >>> > i want to deliver my program, which runs perfectly 'uncompiled', as an >>> > exe file to customers. >>> > >>> > The problem: i have to use an activeX component in a windows-form, and >>> > com-components can only be created in single-thread apartments. >>> > But when i use py2exe to compile it, the application is run in a multi- >>> > threaded-apartment >>> > (System.Threading.Thread.CurrentThread.GetApartmentState() is MTA). >>> > >>> > I tried some workarounds, e.g. create the form in an STA-thread or >>> > create the activex in an STA like this: >>> > >>> > thread_is_ready = False >>> > axBrowser = None >>> > def create_browser_thread(*args): >>> > global thread_is_ready >>> > global axBrowser >>> > print System.Threading.Thread.CurrentThread.GetApartmentState() >>> > axBrowser = AxSHDocVw.AxWebBrowser() >>> > thread_is_ready = True >>> > >>> > #and the initialization function in my main form class: >>> > def InitializeComponent(self): >>> > global thread_is_ready >>> > global axBrowser >>> > job = System.Threading.ThreadStart(create_browser_thread) >>> > thread = System.Threading.Thread(job) >>> > thread.SetApartmentState(System.Threading.ApartmentState.STA) >>> > thread.Start() >>> > while not thread_is_ready: >>> > pass >>> > self.Controls.Add(axBrowser) >>> > >>> > This all worked fine when run with python.exe from command-line. >>> > However, compiled with py2exe, the initialization function ends >>> > without exceptions, but the form is not shown and the program hangs. >>> > Telling the form to shop does not help either. >>> > >>> > Did anyone experience similar problems? >>> > >>> > best regards, >>> > Pablo >>> > _________________________________________________ >>> > Python.NET mailing list - PythonDotNet at python.org >>> > http://mail.python.org/mailman/listinfo/pythondotnet >> >> -------------------------- >> Brian Lloyd >> >> brian.lloyd at revolutionhealth.com >> >> _________________________________________________ >> Python.NET mailing list - PythonDotNet at python.org >> http://mail.python.org/mailman/listinfo/pythondotnet >> > > -------------------------- Brian Lloyd brian.lloyd at revolutionhealth.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20080103/3fba395f/attachment.htm From dan at thetrowbridgefamily.com Tue Jan 8 03:10:08 2008 From: dan at thetrowbridgefamily.com (Dan Trowbridge) Date: Mon, 7 Jan 2008 21:10:08 -0500 Subject: [Python.NET] Memory Leak in MFC/C++ based Python Extended/Embedded code. Message-ID: Hi all, I have a MS Windows/MFC based C++ code that I have implemented Python embedding/extending in. (I am using Visual Studio 2003.) The code seems to do what I have intended except it always reports a memory leak when it exits. I tried all kinds of things but there did not seem to be anything I could do to get rid of it. So... I built a new MFC project and the only things I added was... #include at the top of the application class .cpp file and the following two lines Py_Initialize(); Py_Finalize(); in the application class constructor. The minimal code STILL reports a memory error. It looks like the memory leak had nothing to do with my code. Anybody have any ideas how to fix this? Background: I am using Python 2.5.1. I am not using BOOST::PYTHON (I am using BOOST::NUMERIC and BOOST::SHARED_PTR for other things in the code - maybe I should use BOOST::PYTHON - maybe their shared_ptr's would take care of this for me? ). I also am not using SWIG or any other "helpers". Any help would be greatly appreciated. If this is not the right forum please advise where to post this. It got to figure that someone has seen this before - considering as long as Python has been around and as big as the developer community is. Thanks in advance for your collective help. Dannyt From brian.lloyd at revolutionhealth.com Tue Jan 8 15:19:47 2008 From: brian.lloyd at revolutionhealth.com (Brian Lloyd) Date: Tue, 08 Jan 2008 09:19:47 -0500 Subject: [Python.NET] Memory Leak in MFC/C++ based Python Extended/Embedded code. In-Reply-To: Message-ID: Hi Dan - for regular Python embedding questions you'd be better off asking on the standard Python list (this list is for an integration of Python with .NET). -Brian On 1/7/08 9:10 PM, "Dan Trowbridge" wrote: > Hi all, > > I have a MS Windows/MFC based C++ code that I have implemented Python > embedding/extending in. (I am using Visual Studio 2003.) The code seems to > do what I have intended except it always reports a memory leak when it > exits. I tried all kinds of things but there did not seem to be anything I > could do to get rid of it. > > So... > > I built a new MFC project and the only things I added was... > > #include > > at the top of the application class .cpp file and the following two lines > > Py_Initialize(); > Py_Finalize(); > > in the application class constructor. > > The minimal code STILL reports a memory error. It looks like the memory > leak had nothing to do with my code. > > Anybody have any ideas how to fix this? > > Background: I am using Python 2.5.1. I am not using BOOST::PYTHON (I am > using BOOST::NUMERIC and BOOST::SHARED_PTR for other things in the code - > maybe I should use BOOST::PYTHON - maybe their shared_ptr's would take care > of this for me? ). I also am not using SWIG or any other "helpers". > > Any help would be greatly appreciated. If this is not the right forum > please advise where to post this. > > It got to figure that someone has seen this before - considering as long as > Python has been around and as big as the developer community is. > > Thanks in advance for your collective help. > > Dannyt > > > > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet -------------------------- Brian Lloyd brian.lloyd at revolutionhealth.com From adrian at cadifra.com Wed Jan 9 20:18:56 2008 From: adrian at cadifra.com (Adrian Buehlmann) Date: Wed, 09 Jan 2008 20:18:56 +0100 Subject: [Python.NET] pythonnet-2.0-alpha2: PyString cannot create 8-bit Python strings Message-ID: <47851E20.4070506@cadifra.com> Hi all While trying to call Python code from within C# using "Python.Runtime" from pythonnet-2.0-alpha2, I ran into a problem using "PyString", which can only create *unicode* python strings and I needed a way to create 8-bit (single byte character) Python strings in order to call "PyObject.Invoke(PyTuple, PyDict)". Detailed report follows below. [Side note: .Net "string" (which is "System.String") is a unicode string] I've tried calling Python code from within C# code using: Python.Runtime.PyObject.Invoke(PyTuple, PyDict) I prepared the PyDict by using: Python.Runtime.PyObject.this[string] The original code I tried was: PythonEngine.Initialize(); IntPtr lck = PythonEngine.AcquireLock(); PyObject mod_builtin = PythonEngine.ImportModule("__builtin__"); PyObject False = mod_builtin.GetAttr("False"); PyObject mod_hg = PythonEngine.ImportModule("mercurial"); PyObject mod_ui = PythonEngine.ImportModule("mercurial.ui"); PyObject ui_ctor = mod_ui.GetAttr("ui"); PyDict d = new PyDict(); d["interactive"] = False; PyTuple noargs = new PyTuple(); PyObject ui = ui_ctor.Invoke(noargs, d); (For the Mercurial details see: http://www.selenic.com/mercurial/wiki/ http://selenic.com/repo/hg/file/23889160905a/mercurial/ui.py) The relevant called python code is: class ui(object): def __init__(self, verbose=False, debug=False, quiet=False, interactive=True, traceback=False, report_untrusted=True, parentui=None): Problem is, my code-snip-1 didn't work, because that adds a *unicode* key string to the dict, because it uses: Python.Runtime.PyString.PyString(string) which creates a *unicode" python string. But Invoke() works only when using 8-bit (single byte) strings for the keys in the dict. To fix this I changed "src/runtime/pydict.cs" (mercurial patch): # HG changeset patch # User Adrian Buehlmann # Date 1199891100 -3600 # Node ID 89623ba76fd3d72c56e05981f2504dd2872560fb # Parent 3c3b7151ad596a4e6cf3012c33246418c641a66d New SetItemString() on PyDict diff -r 3c3b7151ad59 -r 89623ba76fd3 runtime/pydict.cs --- a/runtime/pydict.cs Wed Jan 09 15:59:24 2008 +0100 +++ b/runtime/pydict.cs Wed Jan 09 16:05:00 2008 +0100 @@ -201,6 +201,22 @@ namespace Python.Runtime { public void Clear() { Runtime.PyDict_Clear(obj); } + + + /// + /// SetItemString Method + /// + /// + /// + /// Inserts value into this dictionary using ansi string key as a key. + /// + + public void SetItemString(string key, PyObject value) { + int result = Runtime.PyDict_SetItemString(obj, key, value.obj); + if (result < 0) { + throw new PythonException(); + } + } } which adds a new SetItemString() method to PyDict and then did: PythonEngine.Initialize(); IntPtr lck = PythonEngine.AcquireLock(); PyObject mod_builtin = PythonEngine.ImportModule("__builtin__"); PyObject False = mod_builtin.GetAttr("False"); PyObject mod_hg = PythonEngine.ImportModule("mercurial"); PyObject mod_ui = PythonEngine.ImportModule("mercurial.ui"); PyObject ui_ctor = mod_ui.GetAttr("ui"); PyDict d = new PyDict(); d.SetItemString("interactive", False); PyTuple noargs = new PyTuple(); PyObject ui = ui_ctor.Invoke(noargs, d); I didn't see a better way to create a PyObject that represents an ansi python string. With PyString I can only create *unicode* python strings. I was tempted to do: public PyString(string s) : base() { // obj = Runtime.PyUnicode_FromUnicode(s, s.Length); // orig code obj = Runtime.PyString_FromString(s); // create ansi string instead if (obj == IntPtr.Zero) { throw new PythonException(); } } but that would break existing code (not mine). Adrian From mkozyarchuk at funddevelopmentservices.com Thu Jan 10 04:08:51 2008 From: mkozyarchuk at funddevelopmentservices.com (Maksim Kozyarchuk) Date: Wed, 09 Jan 2008 22:08:51 -0500 Subject: [Python.NET] Errors with Python.Net 2.0 SP 1 Message-ID: Getting the following exception when attempting to bind a python delegate to an event handler. Has anyone come across this before? Unhandled Exception: System.TypeInitializationException: The type initializer for 'Python.Runtime.CodeGenerator' threw an exception. ---> System.InvalidCastException: Unable to cast object of type 'System.Reflection.Module' to type 'System.Reflection.Emit.ModuleBuilder'. at System.Reflection.Emit.AssemblyBuilderData.GetInMemoryAssemblyModule() at System.AppDomain.InternalDefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, StackCrawlMark& stackMark, IEnumerable`1 unsafeAssemblyAttributes) at System.AppDomain.DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access) at Python.Runtime.CodeGenerator..cctor() in C:\workspace2\Python.Net\runtime\codegenerator.cs:line 37 --- End of inner exception stack trace --- at Python.Runtime.DelegateManager.GetDispatcher(Type dtype) in C:\workspace2\Python.Net\runtime\delegatemanager.cs:line 79 at Python.Runtime.DelegateManager.GetDelegate(Type dtype, IntPtr callable) in C:\workspace2\Python.Net\runtime\delegatemanager.cs:line 168 at Python.Runtime.EventObject.AddEventHandler(IntPtr target, IntPtr handler) in C:\workspace2\Python.Net\runtime\eventobject.cs:line 49 at Python.Runtime.EventBinding.nb_inplace_add(IntPtr ob, IntPtr arg) in C:\workspace2\Python.Net\runtime\eventbinding.cs:line 44 Here is a simple script that demonstrates this error >>>> from System.Windows.Forms import Application def global_exception_handler(sender, event_args): print "GOT AN EXCEPTION" print event_args.Exception Application.ThreadException += global_exception_handler >>>> -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20080109/c9b72c70/attachment.htm From nico_ml at mgdesign.fr Tue Jan 22 10:22:49 2008 From: nico_ml at mgdesign.fr (Nicolas Lelong) Date: Tue, 22 Jan 2008 10:22:49 +0100 Subject: [Python.NET] current PythonEngine.RunString implementation Message-ID: <002801c85cd8$5b4aa8d0$d100a8c0@nicopc> Hello ! First of all, thanks for your work on Python.NET ; I'm a new user, and I'm quite pleased with the abilities of this library ! I'm currently setting up a project aiming at dynamic GUI creation for python objects of an existing codebase. So far, I've been able to make some bootstrapping work, allowing me to view and edit arbitrary python objects using MS PropertyGrid control. The application I'm working on already embeds a Python interpreter, and I've been able to also embed Python.NET and seamlessly make all this communicate without too much problems. The only point I had to tweak was PythonEngine.RunString code : the original code calls "PyEval_GetGlobals" which invariably crashed my application. Moreover, I needed a version of RunString that used "Py_eval_input". I tried to write my own version of RunString using Python.Runtime.Runtime methods, but as they are marked as 'internal', all I could do is patch python.NET code. For now, I rewrote another version of RunString, which looks similar to the RunString code that is often recommanded :: Index: pythonengine.cs =================================================================== --- pythonengine.cs (r?vision 90) +++ pythonengine.cs (copie de travail) @@ -314,23 +314,24 @@ /// public static PyObject RunString(string code) { - IntPtr globals = Runtime.PyEval_GetGlobals(); - IntPtr locals = Runtime.PyDict_New(); + return RunString(code, Runtime.Py_file_input); + } - IntPtr builtins = Runtime.PyEval_GetBuiltins(); - Runtime.PyDict_SetItemString(locals, "__builtins__", builtins); + public static PyObject RunString(string code, IntPtr flags) + { + IntPtr main_module = Runtime.PyImport_AddModule("__main__"); + IntPtr main_namespace = Runtime.PyModule_GetDict(main_module); - IntPtr flag = (IntPtr)257; /* Py_file_input */ - IntPtr result = Runtime.PyRun_String(code, flag, globals, locals); - Runtime.Decref(locals); - if (result == IntPtr.Zero) { + IntPtr result = Runtime.PyRun_String(code, flags, main_namespace, main_namespace); + + if (result == IntPtr.Zero) + { return null; } return new PyObject(result); } - } It seems that there is often people having problems with a default unique RunString implementation. As I'd prefer not to have to maintain my own set of patches to Python.NET, I was wondering if it could be possible to remove the 'internal' modifiers on Python.Runtime.Runtime methods so that everyone out there could use them, at their own risk, to create custom python interaction functionalities ? Any toughts ? Thanks in advance, cheers, Nicolas. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20080122/d0f01c11/attachment.htm From Sathish.Kaveripakam at phonak.com Tue Jan 22 16:53:32 2008 From: Sathish.Kaveripakam at phonak.com (Kaveripakam, Sathish) Date: Tue, 22 Jan 2008 16:53:32 +0100 Subject: [Python.NET] importing the dll using Python on net 2.0 Message-ID: Hi All, I was using a setup wherein I have python scripts importing the C# dll (on Python on net 1.0 and Dll is compiled on .nET 1.0) Now, my new input dll is compiled for .NET 2.0. To ensure my python scripts import the C# dll , I started to use the Python ON net 2.0 Alpha 2 version.But I am having problems in importing the dll . Here is my snapshot of the code which used to work using python on net1.0: import CLR.System.Reflection import Assembly def load(): name= "x1.dll" Assembly.LoadFrom(name) import CLR.x.y.z as z return; When the above sample code is compiled on python on net 2.0, I got a warning "DeprecationWarning: Importing from the CLR.* namespace is deprecated" and it gives DLL Exception, when I try to use the elements of the dll. Hence I was wondering does the Version 2.0 of python on net has any special way of porting the dll's compiled on .NET 2.0. Could any one please let me know, how to handle the CLR issues on Python On net 2.0 ? PS:- I could able to add the reference for the above dll in a stand alone C# project and I havent found any problems. Regards, ******************** Legal Notice: The information in this electronic transmission may contain confidential or legally privileged information and is intended solely for the individual(s) named above. If you are not an intended recipient or an authorized agent, you are hereby notified that reading, distributing, or otherwise disseminating, copying or taking any action based on the contents of this transmission is strictly prohibited. Any unauthorized interception of this transmission is illegal under law. If you have received this transmission in error, please notify the sender by telephone [at the number indicated above/ on +41 58 928 0101] as soon as possible and then destroy all copies of this transmission. ******************** -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20080122/c54d300a/attachment.htm From lists at cheimes.de Tue Jan 22 18:59:34 2008 From: lists at cheimes.de (Christian Heimes) Date: Tue, 22 Jan 2008 18:59:34 +0100 Subject: [Python.NET] importing the dll using Python on net 2.0 In-Reply-To: References: Message-ID: <47962F06.3070303@cheimes.de> Kaveripakam, Sathish wrote: > Hence I was wondering does the Version 2.0 of python on net has any > special way of porting the dll's compiled on .NET 2.0. Could any one > please let me know, how to handle the CLR issues on Python On net 2.0 ? You don't need to fiddle around with Reflection. PythonDotNet's clr module contains the function AddReference(). It loads an assembly and makes its namespaces available to Python. import clr clr.AddReference("x1") from x.y.z as z Christian From lists at cheimes.de Tue Jan 22 18:59:34 2008 From: lists at cheimes.de (Christian Heimes) Date: Tue, 22 Jan 2008 18:59:34 +0100 Subject: [Python.NET] importing the dll using Python on net 2.0 In-Reply-To: References: Message-ID: <47962F06.3070303@cheimes.de> Kaveripakam, Sathish wrote: > Hence I was wondering does the Version 2.0 of python on net has any > special way of porting the dll's compiled on .NET 2.0. Could any one > please let me know, how to handle the CLR issues on Python On net 2.0 ? You don't need to fiddle around with Reflection. PythonDotNet's clr module contains the function AddReference(). It loads an assembly and makes its namespaces available to Python. import clr clr.AddReference("x1") from x.y.z as z Christian From nico_ml at mgdesign.fr Thu Jan 24 11:54:58 2008 From: nico_ml at mgdesign.fr (Nicolas Lelong) Date: Thu, 24 Jan 2008 11:54:58 +0100 Subject: [Python.NET] Errors with Python.Net 2.0 SP 1 Message-ID: <002d01c85e77$9024a920$d100a8c0@nicopc> Hi, I have the same problem here since this morning, as XP installed automatically the .NET 2.0 SP 1 update. Unit test 'leaktest.py' illustrated the problem :: H:\temp\pythonnet\pythonnet_orig\src\tests>..\..\python.exe leaktest.py Running module leak check... start: 16109568 end: 17137664 diff: +1028096 Running class leak check... Unhandled Exception: System.TypeInitializationException: The type initializer for 'Python.Runtime.CodeGenerator' threw an exception. -- -> System.InvalidCastException: Unable to cast object of type 'System.Reflection.Module' to type 'System.Reflection.Emit.ModuleBuilder'. at System.Reflection.Emit.AssemblyBuilderData.GetInMemoryAssemblyModule() at System.AppDomain.InternalDefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, StackCrawlMark& stackMark, IEnumerable`1 unsafeAssemblyAttributes) at System.AppDomain.DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access) at Python.Runtime.CodeGenerator..cctor() in H:\temp\pythonnet\pythonnet_orig\src\runtime\codegenerator.cs:line 37 --- End of inner exception stack trace --- at Python.Runtime.DelegateManager.GetDispatcher(Type dtype) in H:\temp\pythonnet\pythonnet_orig\src\runtime\delegatemanager.cs:line 79 at Python.Runtime.DelegateManager.GetDelegate(Type dtype, IntPtr callable) in H:\temp\pythonnet\pythonnet_orig\src\runtime\delegatemanager.cs:line 168 at Python.Runtime.DelegateObject.tp_new(IntPtr tp, IntPtr args, IntPtr kw) in H:\temp\pythonnet\pythonnet_orig\src\runtime\delegateobject.cs:line 74 at e__NativeCall.Call_3(IntPtr , IntPtr , IntPtr , IntPtr ) at Python.Runtime.MetaType.tp_call(IntPtr tp, IntPtr args, IntPtr kw) in H:\temp\pythonnet\pythonnet_orig\src\runtime\metatype.cs:line 156 at Python.Runtime.Runtime.Py_Main(Int32 argc, String[] argv) at Python.Runtime.PythonConsole.Main(String[] args) in H:\temp\pythonnet\pythonnet_orig\src\console\pythonconsole.cs:line 24 I think, for now, I will uninstall this SP1... Cheers, Nicolas. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20080124/fb2d3e36/attachment.htm From nico_ml at mgdesign.fr Fri Jan 25 09:44:08 2008 From: nico_ml at mgdesign.fr (Nicolas Lelong) Date: Fri, 25 Jan 2008 09:44:08 +0100 Subject: [Python.NET] Errors with Python.Net 2.0 SP 1 References: <002d01c85e77$9024a920$d100a8c0@nicopc> Message-ID: <004f01c85f2e$736a2690$d100a8c0@nicopc> After having setup a minimum repro case for a MSDN Forum (http://forums.microsoft.com/Forums/ShowPost.aspx?PostID=2735385&SiteID=1), I came up with a simple workaround that suits me for now... The problems comes for the AssemblyManager, it seems that on dynamic Assemblies, the AssemblyLoad event is called before the Assembly object is properly set up, and that the GetTypes() call issued in ScanAssembly messes up the internal state of the newly created Assembly.... As, dynamic assemblies are empty when created, there's no point is scanning them - at least, this is the case of assemblies created by Python.Runtime.CodeGenerator and Python.Runtime.NativeCall. So, checking is an assembly is dynamic before calling ScanAssembly does the trick, see the following patch : Index: pythonnet/src/runtime/assemblymanager.cs =================================================================== --- pythonnet/src/runtime/assemblymanager.cs (r?vision 90) +++ pythonnet/src/runtime/assemblymanager.cs (copie de travail) @@ -87,7 +87,12 @@ static void AssemblyLoadHandler(Object ob, AssemblyLoadEventArgs args){ Assembly assembly = args.LoadedAssembly; assemblies.Add(assembly); - ScanAssembly(assembly); + // .NET v2.0 SP1 bug workaround ; ScanAssembly called on newly created DynamicAssembly causes problems + // only scan non-dynamic assemblies... + if ( !(assembly is System.Reflection.Emit.AssemblyBuilder) ) + { + ScanAssembly(assembly); + } } It fixes the issue, as I'm quite new to .NET I may miss something obvious... Any thoughts ? Cheers, Nicolas. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20080125/3f30ee74/attachment.htm From Sathish.Kaveripakam at phonak.com Mon Jan 28 22:32:11 2008 From: Sathish.Kaveripakam at phonak.com (Kaveripakam, Sathish) Date: Mon, 28 Jan 2008 22:32:11 +0100 Subject: [Python.NET] Impoting the dll in python 2.0 Message-ID: An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20080128/067c106f/attachment.htm From Sathish.Kaveripakam at phonak.com Thu Jan 31 17:58:35 2008 From: Sathish.Kaveripakam at phonak.com (Kaveripakam, Sathish) Date: Thu, 31 Jan 2008 17:58:35 +0100 Subject: [Python.NET] converting Pyobject to user defined type data structures Message-ID: Hi All, I am reading a PyObject from Python in C#. In C# code, I would like to convert the PyObject to the user defined type. In this regard, I used the call: x = (usrDefinedType) Convert.ChangeType(pyObjectInstance,typeof(usrDefinedType)); The compilation went on fine, but during runtime, I got an error saying: "Object must implement IConvertible". I was wondering, is there any other way to convert the PyObjects to userdefined types ? Regards ******************** Legal Notice: The information in this electronic transmission may contain confidential or legally privileged information and is intended solely for the individual(s) named above. If you are not an intended recipient or an authorized agent, you are hereby notified that reading, distributing, or otherwise disseminating, copying or taking any action based on the contents of this transmission is strictly prohibited. Any unauthorized interception of this transmission is illegal under law. If you have received this transmission in error, please notify the sender by telephone [at the number indicated above/ on +41 58 928 0101] as soon as possible and then destroy all copies of this transmission. ******************** -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/pythondotnet/attachments/20080131/9d81d1c7/attachment.htm