From rpigneri at LavaStorm.com Fri Feb 1 00:19:19 2008 From: rpigneri at LavaStorm.com (Pigneri, Rocco) Date: Thu, 31 Jan 2008 18:19:19 -0500 Subject: [IronPython] IronPython Studio in Intergrated Mode Message-ID: Dear all, Is there a way to install IronPython Studio in integrated mode? I checked the website and couldn't find any information about it. My goal in doing this is to build an assembly in C# and then consume it in IronPython. Thank you, Rocco -------------- next part -------------- An HTML attachment was scrubbed... URL: From curt at hagenlocher.org Sat Feb 2 16:50:13 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Sat, 2 Feb 2008 07:50:13 -0800 Subject: [IronPython] Template argument type inference Message-ID: Is it expected that the DLR and/or IronPython will eventually try to infer template arguments when calling a generically-defined functions? PS F:\IPCE-r7\ipy2> *.\ipy.exe* IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.1433 Copyright (c) Microsoft Corporation. All rights reserved. >>> *import clr* >>> *clr.AddReferenceByPartialName('xunit') *>>> *from Xunit import Assert *>>> *Assert.Equal(1, 1) *Traceback (most recent call last): File , line unknown, in ##137 TypeError: Equal() takes at least 2147483647 arguments (2 given) >>> *Assert.Equal[type(1)](1, 1) *>>> Should I file a CodePlex issue for that rather unintuitive error message? -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From sanxiyn at gmail.com Sun Feb 3 03:56:59 2008 From: sanxiyn at gmail.com (Sanghyeon Seo) Date: Sun, 3 Feb 2008 11:56:59 +0900 Subject: [IronPython] PyYAML on IronPython Message-ID: <5b0248170802021856m7b0a710bx501326c21a3a2cdf@mail.gmail.com> Hello the IronPython list and yaml-core list, Some of you may want to investigate PyYAML on IronPython test failures, performance, etc. $ svn co http://svn.pyyaml.org/pyyaml/trunk pyyaml $ cd pyyaml $ PYTHONPATH=lib python tests/test_yaml.py # Python 2.4 Ran 1210 tests in 4.638s OK $ IRONPYTHONPATH=lib ipy tests/test_yaml.py # IronPython 1 Ran 1210 tests in 36.698s FAILED (failures=8, errors=57) $ IRONPYTHONPATH=lib ipy2 tests/test_yaml.py # IronPython 2 Ran 1210 tests in 61.871s FAILED (failures=7, errors=57) -- Seo Sanghyeon From curt at hagenlocher.org Mon Feb 4 06:38:57 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Sun, 3 Feb 2008 21:38:57 -0800 Subject: [IronPython] Assemblies loaded by default Message-ID: When I run IronPython interactively, I automatically get System.dll loaded: PS f:\IronPython-2.0A8> *.\ipy.exe* IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.1433 Copyright (c) Microsoft Corporation. All rights reserved. >>> *import System* >>> *System.DateTime* >>> But when I run an IronPython script through the hosting api, I don't: C# source contains: SourceUnit source = PythonEngine.CurrentEngine.CreateScriptSourceFromFile(" Class1.py"); IScriptScope m = PythonEngine.CurrentEngine.CreateScope(); PythonEngine.CurrentEngine.Execute(m, source); Class1.py contains: import clr import System Output is: IronPython.Runtime.Exceptions.ImportException : No module named System What do I need to do to my embedding host to make sure it's preloading the same assemblies as the interactive console? -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From miha.valencic at gmail.com Mon Feb 4 07:13:14 2008 From: miha.valencic at gmail.com (Miha Valencic) Date: Mon, 4 Feb 2008 07:13:14 +0100 Subject: [IronPython] Assemblies loaded by default In-Reply-To: References: Message-ID: <233dfa1d0802032213w4f57470re736fe018c3ecb0f@mail.gmail.com> Try "import clr" in your python script. I use Python 1.1 though.. Miha On Feb 4, 2008 6:38 AM, Curt Hagenlocher wrote: > When I run IronPython interactively, I automatically get System.dllloaded: > > > But when I run an IronPython script through the hosting api, I don't: > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From srivatsn at microsoft.com Mon Feb 4 08:41:42 2008 From: srivatsn at microsoft.com (Srivatsn Narayanan) Date: Sun, 3 Feb 2008 23:41:42 -0800 Subject: [IronPython] Assemblies loaded by default In-Reply-To: References: Message-ID: <3FA51E96F92363468CF062D992DC846818C72EE920@NA-EXMSG-C106.redmond.corp.microsoft.com> I think this is all the IronPython interepreter loads: ScriptDomainManager.CurrentManager.LoadAssembly(typeof(string).Assembly); //mscorlib.dll ScriptDomainManager.CurrentManager.LoadAssembly(typeof(System.Diagnostics.Debug).Assembly); //System.dll Srivatsn ________________________________ From: users-bounces at lists.ironpython.com [users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher [curt at hagenlocher.org] Sent: Sunday, February 03, 2008 9:38 PM To: Discussion of IronPython Subject: [IronPython] Assemblies loaded by default When I run IronPython interactively, I automatically get System.dll loaded: PS f:\IronPython-2.0A8> .\ipy.exe IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.1433 Copyright (c) Microsoft Corporation. All rights reserved. >>> import System >>> System.DateTime >>> But when I run an IronPython script through the hosting api, I don't: C# source contains: SourceUnit source = PythonEngine.CurrentEngine.CreateScriptSourceFromFile("Class1.py"); IScriptScope m = PythonEngine.CurrentEngine.CreateScope(); PythonEngine.CurrentEngine.Execute(m, source); Class1.py contains: import clr import System Output is: IronPython.Runtime.Exceptions.ImportException : No module named System What do I need to do to my embedding host to make sure it's preloading the same assemblies as the interactive console? -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From curt at hagenlocher.org Mon Feb 4 15:46:58 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Mon, 4 Feb 2008 06:46:58 -0800 Subject: [IronPython] Assemblies loaded by default In-Reply-To: <3FA51E96F92363468CF062D992DC846818C72EE920@NA-EXMSG-C106.redmond.corp.microsoft.com> References: <3FA51E96F92363468CF062D992DC846818C72EE920@NA-EXMSG-C106.redmond.corp.microsoft.com> Message-ID: Ah, excellent; this helped me to find the source file: src\IronPython\Hosting\PythonCommandLine.cs It actually loads the assemblies for both "string" and " System.Diagnostics.Debug". Thanks! On Feb 3, 2008 11:41 PM, Srivatsn Narayanan wrote: > I think this is all the IronPython interepreter loads: > > > ScriptDomainManager.CurrentManager.LoadAssembly( > typeof(string).Assembly); //mscorlib.dll > > ScriptDomainManager.CurrentManager.LoadAssembly( > typeof(System.Diagnostics.Debug).Assembly); //System.dll > > > Srivatsn > > > ------------------------------ > *From:* users-bounces at lists.ironpython.com [ > users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher [ > curt at hagenlocher.org] > *Sent:* Sunday, February 03, 2008 9:38 PM > *To:* Discussion of IronPython > *Subject:* [IronPython] Assemblies loaded by default > > When I run IronPython interactively, I automatically get System.dllloaded: > > PS f:\IronPython-2.0A8> *.\ipy.exe* > IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.1433 > Copyright (c) Microsoft Corporation. All rights reserved. > >>> *import System* > >>> *System.DateTime* > > >>> > > But when I run an IronPython script through the hosting api, I don't: > > C# source contains: > SourceUnit source = PythonEngine.CurrentEngine.CreateScriptSourceFromFile > ("Class1.py"); > IScriptScope m = PythonEngine.CurrentEngine.CreateScope(); > PythonEngine.CurrentEngine.Execute(m, source); > > Class1.py contains: > import clr > import System > Output is: > IronPython.Runtime.Exceptions.ImportException : No module named System > > What do I need to do to my embedding host to make sure it's preloading the > same assemblies as the interactive console? > > -- > Curt Hagenlocher > curt at hagenlocher.org > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Mon Feb 4 17:17:53 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 4 Feb 2008 08:17:53 -0800 Subject: [IronPython] Assemblies loaded by default In-Reply-To: References: <3FA51E96F92363468CF062D992DC846818C72EE920@NA-EXMSG-C106.redmond.corp.microsoft.com> Message-ID: <7AD436E4270DD54A94238001769C2227010FC893C9FD@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Just FYI but this change reflects a change to the underlying DLR hosting APIs. Under the new hosting APIs the loaded assemblies and there namespaces are reflected through ScriptEnvironment.Globals ScriptScope (and the Python importer now looks there for things to import). It used to be that we'd always load those 2 assemblies but we no longer load any to give the host precise control over what assemblies they inject. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Monday, February 04, 2008 6:47 AM To: Discussion of IronPython Subject: Re: [IronPython] Assemblies loaded by default Ah, excellent; this helped me to find the source file: src\IronPython\Hosting\PythonCommandLine.cs It actually loads the assemblies for both "string" and "System.Diagnostics.Debug". Thanks! On Feb 3, 2008 11:41 PM, Srivatsn Narayanan > wrote: I think this is all the IronPython interepreter loads: ScriptDomainManager.CurrentManager.LoadAssembly( typeof(string).Assembly); //mscorlib.dll ScriptDomainManager.CurrentManager.LoadAssembly( typeof(System.Diagnostics.Debug).Assembly); //System.dll Srivatsn ________________________________ From: users-bounces at lists.ironpython.com [users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher [curt at hagenlocher.org] Sent: Sunday, February 03, 2008 9:38 PM To: Discussion of IronPython Subject: [IronPython] Assemblies loaded by default When I run IronPython interactively, I automatically get System.dll loaded: PS f:\IronPython-2.0A8> .\ipy.exe IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.1433 Copyright (c) Microsoft Corporation. All rights reserved. >>> import System >>> System.DateTime >>> But when I run an IronPython script through the hosting api, I don't: C# source contains: SourceUnit source = PythonEngine.CurrentEngine.CreateScriptSourceFromFile("Class1.py"); IScriptScope m = PythonEngine.CurrentEngine.CreateScope(); PythonEngine.CurrentEngine.Execute(m, source); Class1.py contains: import clr import System Output is: IronPython.Runtime.Exceptions.ImportException : No module named System What do I need to do to my embedding host to make sure it's preloading the same assemblies as the interactive console? -- Curt Hagenlocher curt at hagenlocher.org _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Mon Feb 4 17:18:55 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 4 Feb 2008 08:18:55 -0800 Subject: [IronPython] Template argument type inference In-Reply-To: References: Message-ID: <7AD436E4270DD54A94238001769C2227010FC893C9FE@DF-GRTDANE-MSG.exchange.corp.microsoft.com> A bug on the error message would be great. We haven't talked about inferring template arguments in a long time but it certainly does seem like it could be possible in some cases in the future. If you want to file a feature request for it that'd be great too. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Saturday, February 02, 2008 7:50 AM To: Discussion of IronPython Subject: [IronPython] Template argument type inference Is it expected that the DLR and/or IronPython will eventually try to infer template arguments when calling a generically-defined functions? PS F:\IPCE-r7\ipy2> .\ipy.exe IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.1433 Copyright (c) Microsoft Corporation. All rights reserved. >>> import clr >>> clr.AddReferenceByPartialName('xunit') >>> from Xunit import Assert >>> Assert.Equal(1, 1) Traceback (most recent call last): File , line unknown, in ##137 TypeError: Equal() takes at least 2147483647 arguments (2 given) >>> Assert.Equal[type(1)](1, 1) >>> Should I file a CodePlex issue for that rather unintuitive error message? -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Mon Feb 4 17:22:10 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 4 Feb 2008 08:22:10 -0800 Subject: [IronPython] PyYAML on IronPython In-Reply-To: <5b0248170802021856m7b0a710bx501326c21a3a2cdf@mail.gmail.com> References: <5b0248170802021856m7b0a710bx501326c21a3a2cdf@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227010FC893CA00@DF-GRTDANE-MSG.exchange.corp.microsoft.com> This is a great suggestion - coming up in March we're planning on spending some time looking at app compat so this would be a good time for us to do this. It also looks like it's under a license that would allow us to look at it. It's great to see that we've already fixed 1 problem from 1.1 :) -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Sanghyeon Seo Sent: Saturday, February 02, 2008 6:57 PM To: Discussion of IronPython; yaml-core at lists.sourceforge.net Subject: [IronPython] PyYAML on IronPython Hello the IronPython list and yaml-core list, Some of you may want to investigate PyYAML on IronPython test failures, performance, etc. $ svn co http://svn.pyyaml.org/pyyaml/trunk pyyaml $ cd pyyaml $ PYTHONPATH=lib python tests/test_yaml.py # Python 2.4 Ran 1210 tests in 4.638s OK $ IRONPYTHONPATH=lib ipy tests/test_yaml.py # IronPython 1 Ran 1210 tests in 36.698s FAILED (failures=8, errors=57) $ IRONPYTHONPATH=lib ipy2 tests/test_yaml.py # IronPython 2 Ran 1210 tests in 61.871s FAILED (failures=7, errors=57) -- Seo Sanghyeon _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From curt at hagenlocher.org Mon Feb 4 19:31:10 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Mon, 4 Feb 2008 10:31:10 -0800 Subject: [IronPython] Exporting Python code as an assembly Message-ID: After a bit of spare-time hacking this weekend, I've got a "proof-of-concept" program that takes a Python class and exports it as a (statically-defined) assembly. It uses Pythonic function annotations to signal attributes and input and output types to the wrapper generator. You end up with something like this def Test(object): @ClrAttribute(Xunit.FactAttribute) def WorthlessTest(self): Xunit.Assert.Equal[type(1)](1, 1) @ClrAccepts(System.String, System.Int32) @ClrReturns(System.Int32) def CalculateValue(self, s, i): return len(s) + i The program takes this source and spits out a DLL containing the class "Test" which implements "WorthlessTest" and "CalculateValue". The class itself contains a reference to the actual Python object, and each of the public functions simply delegates to the Pythonic implementation. I'm still working on cleaning up the source a little before releasing it, but was wondering if anyone had some feedback on the design as described so far. What should be changed or implemented in order for this to be more useful to you? Thanks, -Curt -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From kfarmer at thuban.org Mon Feb 4 19:44:42 2008 From: kfarmer at thuban.org (Keith J. Farmer) Date: Mon, 4 Feb 2008 10:44:42 -0800 Subject: [IronPython] Decorators on classes Message-ID: Can I resurrect this forgotten soul? http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 Having just finished working on LINQ to SQL, I'm convinced that future LINQ providers will be making heavy use of .NET attributes not just on properties, but on classes themselves. Being able to express these attributes in IronPython is a tremendous bonus. That there be one and only one way to express these is paramount. From curt at hagenlocher.org Mon Feb 4 19:54:07 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Mon, 4 Feb 2008 10:54:07 -0800 Subject: [IronPython] Decorators on classes In-Reply-To: References: Message-ID: I, too, wish that Python had class decorators. However, given that Python 3000 is decidedly and explicitly not backwards-compatible with Python 2.x, it seems clear that there should eventually be two flavors of IronPython -- 2.x-compatible and 3000-compatible. And I'd be concerned about adding Py3-specific features to IP2x unless Py2x does likewise. On the other hand, what harm can there be in "from future import class_decorators"? On Feb 4, 2008 10:44 AM, Keith J. Farmer wrote: > Can I resurrect this forgotten soul? > http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 > > Having just finished working on LINQ to SQL, I'm convinced that future > LINQ providers will be making heavy use of .NET attributes not just on > properties, but on classes themselves. Being able to express these > attributes in IronPython is a tremendous bonus. That there be one and only > one way to express these is paramount. > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at voidspace.org.uk Mon Feb 4 19:55:32 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Mon, 04 Feb 2008 18:55:32 +0000 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: References: Message-ID: <47A75FA4.5090308@voidspace.org.uk> The interface is pretty much exactly what I had in mind for a similar system. What do the statically defined assemblies do - do they call into the IronPython engine - and if so, for IronPython 1 or 2? If not then are you just compiling Python to static assemblies? To my mind the former is more interesting than the latter... (Although both are interesting of course...) Michael http://www.manning.com/foord Curt Hagenlocher wrote: > After a bit of spare-time hacking this weekend, I've got a > "proof-of-concept" program that takes a Python class and exports it as > a (statically-defined) assembly. It uses Pythonic function > annotations to signal attributes and input and output types to the > wrapper generator. You end up with something like this > > def Test(object): > @ClrAttribute(Xunit.FactAttribute) > def WorthlessTest(self): > Xunit.Assert.Equal[type(1)](1, 1) > > @ClrAccepts(System.String, System.Int32) > @ClrReturns(System.Int32) > def CalculateValue(self, s, i): > return len(s) + i > > The program takes this source and spits out a DLL containing the class > "Test" which implements "WorthlessTest" and "CalculateValue". The > class itself contains a reference to the actual Python object, and > each of the public functions simply delegates to the Pythonic > implementation. > > I'm still working on cleaning up the source a little before releasing > it, but was wondering if anyone had some feedback on the design as > described so far. What should be changed or implemented in order for > this to be more useful to you? > > Thanks, > -Curt > > -- > Curt Hagenlocher > curt at hagenlocher.org > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From fuzzyman at voidspace.org.uk Mon Feb 4 19:58:05 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Mon, 04 Feb 2008 18:58:05 +0000 Subject: [IronPython] Decorators on classes In-Reply-To: References: Message-ID: <47A7603D.8040102@voidspace.org.uk> Class decorators will be in Python 2.6 - but there is a big difference between a Python runtime decorator and .NET compile time attributes. Is it possible to attach attributes at runtime using the reflection API? Michael http://www.manning.com/foord Keith J. Farmer wrote: > Can I resurrect this forgotten soul? http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 > > Having just finished working on LINQ to SQL, I'm convinced that future LINQ providers will be making heavy use of .NET attributes not just on properties, but on classes themselves. Being able to express these attributes in IronPython is a tremendous bonus. That there be one and only one way to express these is paramount. > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From curt at hagenlocher.org Mon Feb 4 20:01:21 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Mon, 4 Feb 2008 11:01:21 -0800 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: <47A75FA4.5090308@voidspace.org.uk> References: <47A75FA4.5090308@voidspace.org.uk> Message-ID: The assemblies call into the IronPython engine (version 2) to load and execute the script. Currently, the script is loaded from the file system, but I'd eventually like to support embedding any required scripts as resources in the assembly, so that the whole thing can be distributed as a single neat package. On Feb 4, 2008 10:55 AM, Michael Foord wrote: > The interface is pretty much exactly what I had in mind for a similar > system. > > What do the statically defined assemblies do - do they call into the > IronPython engine - and if so, for IronPython 1 or 2? If not then are > you just compiling Python to static assemblies? > > To my mind the former is more interesting than the latter... (Although > both are interesting of course...) > > Michael > http://www.manning.com/foord > > > Curt Hagenlocher wrote: > > After a bit of spare-time hacking this weekend, I've got a > > "proof-of-concept" program that takes a Python class and exports it as > > a (statically-defined) assembly. It uses Pythonic function > > annotations to signal attributes and input and output types to the > > wrapper generator. You end up with something like this > > > > def Test(object): > > @ClrAttribute(Xunit.FactAttribute) > > def WorthlessTest(self): > > Xunit.Assert.Equal[type(1)](1, 1) > > > > @ClrAccepts(System.String, System.Int32) > > @ClrReturns(System.Int32) > > def CalculateValue(self, s, i): > > return len(s) + i > > > > The program takes this source and spits out a DLL containing the class > > "Test" which implements "WorthlessTest" and "CalculateValue". The > > class itself contains a reference to the actual Python object, and > > each of the public functions simply delegates to the Pythonic > > implementation. > > > > I'm still working on cleaning up the source a little before releasing > > it, but was wondering if anyone had some feedback on the design as > > described so far. What should be changed or implemented in order for > > this to be more useful to you? > > > > Thanks, > > -Curt > > > > -- > > Curt Hagenlocher > > curt at hagenlocher.org > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at voidspace.org.uk Mon Feb 4 20:07:03 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Mon, 04 Feb 2008 19:07:03 +0000 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: References: <47A75FA4.5090308@voidspace.org.uk> Message-ID: <47A76257.6090307@voidspace.org.uk> Curt Hagenlocher wrote: > The assemblies call into the IronPython engine (version 2) to load and > execute the script. Currently, the script is loaded from the file > system, but I'd eventually like to support embedding any > required scripts as resources in the assembly, so that the whole thing > can be distributed as a single neat package. Great - you beat me to it. :-) If you make this open source then I'll be happy to help on it. Michael Foord http://www.manning.com/foord > > On Feb 4, 2008 10:55 AM, Michael Foord > wrote: > > The interface is pretty much exactly what I had in mind for a similar > system. > > What do the statically defined assemblies do - do they call into the > IronPython engine - and if so, for IronPython 1 or 2? If not then are > you just compiling Python to static assemblies? > > To my mind the former is more interesting than the latter... (Although > both are interesting of course...) > > Michael > http://www.manning.com/foord > > > Curt Hagenlocher wrote: > > After a bit of spare-time hacking this weekend, I've got a > > "proof-of-concept" program that takes a Python class and exports > it as > > a (statically-defined) assembly. It uses Pythonic function > > annotations to signal attributes and input and output types to the > > wrapper generator. You end up with something like this > > > > def Test(object): > > @ClrAttribute(Xunit.FactAttribute) > > def WorthlessTest(self): > > Xunit.Assert.Equal[type(1)](1, 1) > > > > @ClrAccepts(System.String, System.Int32) > > @ClrReturns(System.Int32) > > def CalculateValue(self, s, i): > > return len(s) + i > > > > The program takes this source and spits out a DLL containing the > class > > "Test" which implements "WorthlessTest" and "CalculateValue". The > > class itself contains a reference to the actual Python object, and > > each of the public functions simply delegates to the Pythonic > > implementation. > > > > I'm still working on cleaning up the source a little before > releasing > > it, but was wondering if anyone had some feedback on the design as > > described so far. What should be changed or implemented in > order for > > this to be more useful to you? > > > > Thanks, > > -Curt > > > > -- > > Curt Hagenlocher > > curt at hagenlocher.org > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From curt at hagenlocher.org Mon Feb 4 20:13:46 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Mon, 4 Feb 2008 11:13:46 -0800 Subject: [IronPython] Decorators on classes In-Reply-To: <47A7603D.8040102@voidspace.org.uk> References: <47A7603D.8040102@voidspace.org.uk> Message-ID: Oh! I didn't realize that about 2.6. There is indeed a big difference between a Python runtime decorator and a .NET compile time attribute; in fact, the similarities are superficial at best. .NET attributes are totally static, so there's no way to modify a .NET class definition to add them. The IronPython engine would have to recognize particular class-level Pythonic annotations and use that information to emit a new CLR class to represent the Python class. It already emits CLR classes as needed to represent Python classes. By "as needed", I mean that a specific CLR base class plus a specific set of CLR interfaces will uniquely determine a class to be emitted by IronPython. This class is cached so that -- once generated -- any new Python class definition that matches this set of (CLR base class plus interfaces) will reuse the same CLR class definition. What you'd have to change is to put the class-level attributes onto the generated CLR class, then change caching so that the key is (CLR base class plus interfaces plus attributes). It's definitely doable, but raises intriguing questions about "purity". And you'd also need to consider the impact on the larger DLR. Method-level attributes are an entirely different matter. On Feb 4, 2008 10:58 AM, Michael Foord wrote: > Class decorators will be in Python 2.6 - but there is a big difference > between a Python runtime decorator and .NET compile time attributes. Is > it possible to attach attributes at runtime using the reflection API? > > Michael > http://www.manning.com/foord > > Keith J. Farmer wrote: > > Can I resurrect this forgotten soul? > http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 > > > > Having just finished working on LINQ to SQL, I'm convinced that future > LINQ providers will be making heavy use of .NET attributes not just on > properties, but on classes themselves. Being able to express these > attributes in IronPython is a tremendous bonus. That there be one and only > one way to express these is paramount. > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kfarmer at thuban.org Mon Feb 4 20:28:51 2008 From: kfarmer at thuban.org (Keith J. Farmer) Date: Mon, 4 Feb 2008 11:28:51 -0800 Subject: [IronPython] Decorators on classes References: <47A7603D.8040102@voidspace.org.uk> Message-ID: I've had no problems with not grandfathering in older APIs, and am quite happy to not grandfather in older syntax, either. I agree that IronPython would have to be able to distinguish between CLR attributes and Python decorators, inasmuch as CLR attributes are a static part of the class/member definition. But I don't think it's an insurmountable problem, and solving it in the DLR, actually, would be very useful. I wouldn't expect that class authors would want to change the set of .NET attributes frequently if at all -- it doesn't match how they've been designed and how they've evolved, so creating the attributed base class once (and then having pythonic decorators coming in and out at will) seems like a reasonable approach to me. ________________________________ From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher Sent: Mon 2/4/2008 11:13 AM To: Discussion of IronPython Subject: Re: [IronPython] Decorators on classes Oh! I didn't realize that about 2.6. There is indeed a big difference between a Python runtime decorator and a .NET compile time attribute; in fact, the similarities are superficial at best. .NET attributes are totally static, so there's no way to modify a .NET class definition to add them. The IronPython engine would have to recognize particular class-level Pythonic annotations and use that information to emit a new CLR class to represent the Python class. It already emits CLR classes as needed to represent Python classes. By "as needed", I mean that a specific CLR base class plus a specific set of CLR interfaces will uniquely determine a class to be emitted by IronPython. This class is cached so that -- once generated -- any new Python class definition that matches this set of (CLR base class plus interfaces) will reuse the same CLR class definition. What you'd have to change is to put the class-level attributes onto the generated CLR class, then change caching so that the key is (CLR base class plus interfaces plus attributes). It's definitely doable, but raises intriguing questions about "purity". And you'd also need to consider the impact on the larger DLR. Method-level attributes are an entirely different matter. On Feb 4, 2008 10:58 AM, Michael Foord wrote: Class decorators will be in Python 2.6 - but there is a big difference between a Python runtime decorator and .NET compile time attributes. Is it possible to attach attributes at runtime using the reflection API? Michael http://www.manning.com/foord Keith J. Farmer wrote: > Can I resurrect this forgotten soul? http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 > > Having just finished working on LINQ to SQL, I'm convinced that future LINQ providers will be making heavy use of .NET attributes not just on properties, but on classes themselves. Being able to express these attributes in IronPython is a tremendous bonus. That there be one and only one way to express these is paramount. > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From fuzzyman at voidspace.org.uk Mon Feb 4 20:53:17 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Mon, 04 Feb 2008 19:53:17 +0000 Subject: [IronPython] Decorators on classes In-Reply-To: References: <47A7603D.8040102@voidspace.org.uk> Message-ID: <47A76D2D.2040500@voidspace.org.uk> Keith J. Farmer wrote: > I've had no problems with not grandfathering in older APIs, and am quite happy to not grandfather in older syntax, either. > What do you mean by 'grandfathering' in this context? Michael > > I agree that IronPython would have to be able to distinguish between CLR attributes and Python decorators, inasmuch as CLR attributes are a static part of the class/member definition. But I don't think it's an insurmountable problem, and solving it in the DLR, actually, would be very useful. > > I wouldn't expect that class authors would want to change the set of .NET attributes frequently if at all -- it doesn't match how they've been designed and how they've evolved, so creating the attributed base class once (and then having pythonic decorators coming in and out at will) seems like a reasonable approach to me. > > ________________________________ > > From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher > Sent: Mon 2/4/2008 11:13 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > > Oh! I didn't realize that about 2.6. > > There is indeed a big difference between a Python runtime decorator and a .NET compile time attribute; in fact, the similarities are superficial at best. > > .NET attributes are totally static, so there's no way to modify a .NET class definition to add them. The IronPython engine would have to recognize particular class-level Pythonic annotations and use that information to emit a new CLR class to represent the Python class. It already emits CLR classes as needed to represent Python classes. By "as needed", I mean that a specific CLR base class plus a specific set of CLR interfaces will uniquely determine a class to be emitted by IronPython. This class is cached so that -- once generated -- any new Python class definition that matches this set of (CLR base class plus interfaces) will reuse the same CLR class definition. > > What you'd have to change is to put the class-level attributes onto the generated CLR class, then change caching so that the key is (CLR base class plus interfaces plus attributes). It's definitely doable, but raises intriguing questions about "purity". And you'd also need to consider the impact on the larger DLR. > > Method-level attributes are an entirely different matter. > > On Feb 4, 2008 10:58 AM, Michael Foord wrote: > > > Class decorators will be in Python 2.6 - but there is a big difference > between a Python runtime decorator and .NET compile time attributes. Is > it possible to attach attributes at runtime using the reflection API? > > Michael > http://www.manning.com/foord > > > Keith J. Farmer wrote: > > Can I resurrect this forgotten soul? http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 > > > > Having just finished working on LINQ to SQL, I'm convinced that future LINQ providers will be making heavy use of .NET attributes not just on properties, but on classes themselves. Being able to express these attributes in IronPython is a tremendous bonus. That there be one and only one way to express these is paramount. > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From kfarmer at thuban.org Mon Feb 4 22:40:04 2008 From: kfarmer at thuban.org (Keith J. Farmer) Date: Mon, 4 Feb 2008 13:40:04 -0800 Subject: [IronPython] Decorators on classes References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> Message-ID: Grandfathering: Giving more consideration to retaining compatibility than it deserves. :) Obviously, IronPython should prioritize compatibility with Py2.4, but for obvious reasons I limit that to seeing IP as a consumer of CPy, not the other way around. On the other hand, IP must also be able to consume .NET, and .NET is increasingly making use of things the IP cannot yet express. (I thought of another framework that attributes are used on -- WCF. There are also XML serialization attributes.) To that end, I think it would be worthwhile, for the purpose of .NET attributes, to have decorators or their analogues available to IronPython in the current stage of development. That is, I think it should be that IronPython = CPy 2.4 + .NET Attributes + other .NET-isms expressed in a Pythonic way. ________________________________ From: users-bounces at lists.ironpython.com on behalf of Michael Foord Sent: Mon 2/4/2008 11:53 AM To: Discussion of IronPython Subject: Re: [IronPython] Decorators on classes Keith J. Farmer wrote: > I've had no problems with not grandfathering in older APIs, and am quite happy to not grandfather in older syntax, either. > What do you mean by 'grandfathering' in this context? Michael > > I agree that IronPython would have to be able to distinguish between CLR attributes and Python decorators, inasmuch as CLR attributes are a static part of the class/member definition. But I don't think it's an insurmountable problem, and solving it in the DLR, actually, would be very useful. > > I wouldn't expect that class authors would want to change the set of .NET attributes frequently if at all -- it doesn't match how they've been designed and how they've evolved, so creating the attributed base class once (and then having pythonic decorators coming in and out at will) seems like a reasonable approach to me. > > ________________________________ > > From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher > Sent: Mon 2/4/2008 11:13 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > > Oh! I didn't realize that about 2.6. > > There is indeed a big difference between a Python runtime decorator and a .NET compile time attribute; in fact, the similarities are superficial at best. > > .NET attributes are totally static, so there's no way to modify a .NET class definition to add them. The IronPython engine would have to recognize particular class-level Pythonic annotations and use that information to emit a new CLR class to represent the Python class. It already emits CLR classes as needed to represent Python classes. By "as needed", I mean that a specific CLR base class plus a specific set of CLR interfaces will uniquely determine a class to be emitted by IronPython. This class is cached so that -- once generated -- any new Python class definition that matches this set of (CLR base class plus interfaces) will reuse the same CLR class definition. > > What you'd have to change is to put the class-level attributes onto the generated CLR class, then change caching so that the key is (CLR base class plus interfaces plus attributes). It's definitely doable, but raises intriguing questions about "purity". And you'd also need to consider the impact on the larger DLR. > > Method-level attributes are an entirely different matter. > > On Feb 4, 2008 10:58 AM, Michael Foord wrote: > > > Class decorators will be in Python 2.6 - but there is a big difference > between a Python runtime decorator and .NET compile time attributes. Is > it possible to attach attributes at runtime using the reflection API? > > Michael > http://www.manning.com/foord > > > Keith J. Farmer wrote: > > Can I resurrect this forgotten soul? http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 > > > > Having just finished working on LINQ to SQL, I'm convinced that future LINQ providers will be making heavy use of .NET attributes not just on properties, but on classes themselves. Being able to express these attributes in IronPython is a tremendous bonus. That there be one and only one way to express these is paramount. > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From dinov at exchange.microsoft.com Mon Feb 4 22:49:36 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 4 Feb 2008 13:49:36 -0800 Subject: [IronPython] Decorators on classes In-Reply-To: References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> Message-ID: <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> FYI IP 2.0 is tracking 2.5 and we have the big pieces in place plus many small pieces (although there's more to go). In 1.1 we had -X:Python25 which enabled selective 2.5 features and we could conceptually do the same sort of thing for 2.0 so that it includes one or two 2.6 features such as class decorators. >From there the decorators to support attributes could even be written in Python. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Keith J. Farmer Sent: Monday, February 04, 2008 1:40 PM To: Discussion of IronPython; Discussion of IronPython Subject: Re: [IronPython] Decorators on classes Grandfathering: Giving more consideration to retaining compatibility than it deserves. :) Obviously, IronPython should prioritize compatibility with Py2.4, but for obvious reasons I limit that to seeing IP as a consumer of CPy, not the other way around. On the other hand, IP must also be able to consume .NET, and .NET is increasingly making use of things the IP cannot yet express. (I thought of another framework that attributes are used on -- WCF. There are also XML serialization attributes.) To that end, I think it would be worthwhile, for the purpose of .NET attributes, to have decorators or their analogues available to IronPython in the current stage of development. That is, I think it should be that IronPython = CPy 2.4 + .NET Attributes + other .NET-isms expressed in a Pythonic way. ________________________________ From: users-bounces at lists.ironpython.com on behalf of Michael Foord Sent: Mon 2/4/2008 11:53 AM To: Discussion of IronPython Subject: Re: [IronPython] Decorators on classes Keith J. Farmer wrote: > I've had no problems with not grandfathering in older APIs, and am quite happy to not grandfather in older syntax, either. > What do you mean by 'grandfathering' in this context? Michael > > I agree that IronPython would have to be able to distinguish between CLR attributes and Python decorators, inasmuch as CLR attributes are a static part of the class/member definition. But I don't think it's an insurmountable problem, and solving it in the DLR, actually, would be very useful. > > I wouldn't expect that class authors would want to change the set of .NET attributes frequently if at all -- it doesn't match how they've been designed and how they've evolved, so creating the attributed base class once (and then having pythonic decorators coming in and out at will) seems like a reasonable approach to me. > > ________________________________ > > From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher > Sent: Mon 2/4/2008 11:13 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > > Oh! I didn't realize that about 2.6. > > There is indeed a big difference between a Python runtime decorator and a .NET compile time attribute; in fact, the similarities are superficial at best. > > .NET attributes are totally static, so there's no way to modify a .NET class definition to add them. The IronPython engine would have to recognize particular class-level Pythonic annotations and use that information to emit a new CLR class to represent the Python class. It already emits CLR classes as needed to represent Python classes. By "as needed", I mean that a specific CLR base class plus a specific set of CLR interfaces will uniquely determine a class to be emitted by IronPython. This class is cached so that -- once generated -- any new Python class definition that matches this set of (CLR base class plus interfaces) will reuse the same CLR class definition. > > What you'd have to change is to put the class-level attributes onto the generated CLR class, then change caching so that the key is (CLR base class plus interfaces plus attributes). It's definitely doable, but raises intriguing questions about "purity". And you'd also need to consider the impact on the larger DLR. > > Method-level attributes are an entirely different matter. > > On Feb 4, 2008 10:58 AM, Michael Foord wrote: > > > Class decorators will be in Python 2.6 - but there is a big difference > between a Python runtime decorator and .NET compile time attributes. Is > it possible to attach attributes at runtime using the reflection API? > > Michael > http://www.manning.com/foord > > > Keith J. Farmer wrote: > > Can I resurrect this forgotten soul? http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 > > > > Having just finished working on LINQ to SQL, I'm convinced that future LINQ providers will be making heavy use of .NET attributes not just on properties, but on classes themselves. Being able to express these attributes in IronPython is a tremendous bonus. That there be one and only one way to express these is paramount. > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From fuzzyman at voidspace.org.uk Mon Feb 4 23:02:32 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Mon, 04 Feb 2008 22:02:32 +0000 Subject: [IronPython] Decorators on classes In-Reply-To: <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <47A78B78.4070903@voidspace.org.uk> Dino Viehland wrote: > FYI IP 2.0 is tracking 2.5 and we have the big pieces in place plus many small pieces (although there's more to go). In 1.1 we had -X:Python25 which enabled selective 2.5 features and we could conceptually do the same sort of thing for 2.0 so that it includes one or two 2.6 features such as class decorators. > > >From there the decorators to support attributes could even be written in Python. > > Is that right - could attributes be added to an IronPython class (or instances) at runtime using reflection? Earlier parts of this conversation implied that this wasn't the case... Decorators are only syntactic sugar, so the lack of class decorators isn't an impediment... Michael > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Keith J. Farmer > Sent: Monday, February 04, 2008 1:40 PM > To: Discussion of IronPython; Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > Grandfathering: Giving more consideration to retaining compatibility than it deserves. :) > > Obviously, IronPython should prioritize compatibility with Py2.4, but for obvious reasons I limit that to seeing IP as a consumer of CPy, not the other way around. On the other hand, IP must also be able to consume .NET, and .NET is increasingly making use of things the IP cannot yet express. (I thought of another framework that attributes are used on -- WCF. There are also XML serialization attributes.) > > To that end, I think it would be worthwhile, for the purpose of .NET attributes, to have decorators or their analogues available to IronPython in the current stage of development. That is, I think it should be that IronPython = CPy 2.4 + .NET Attributes + other .NET-isms expressed in a Pythonic way. > > ________________________________ > > From: users-bounces at lists.ironpython.com on behalf of Michael Foord > Sent: Mon 2/4/2008 11:53 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > > > Keith J. Farmer wrote: > >> I've had no problems with not grandfathering in older APIs, and am quite happy to not grandfather in older syntax, either. >> >> > > What do you mean by 'grandfathering' in this context? > > Michael > > >> I agree that IronPython would have to be able to distinguish between CLR attributes and Python decorators, inasmuch as CLR attributes are a static part of the class/member definition. But I don't think it's an insurmountable problem, and solving it in the DLR, actually, would be very useful. >> >> I wouldn't expect that class authors would want to change the set of .NET attributes frequently if at all -- it doesn't match how they've been designed and how they've evolved, so creating the attributed base class once (and then having pythonic decorators coming in and out at will) seems like a reasonable approach to me. >> >> ________________________________ >> >> From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher >> Sent: Mon 2/4/2008 11:13 AM >> To: Discussion of IronPython >> Subject: Re: [IronPython] Decorators on classes >> >> >> Oh! I didn't realize that about 2.6. >> >> There is indeed a big difference between a Python runtime decorator and a .NET compile time attribute; in fact, the similarities are superficial at best. >> >> .NET attributes are totally static, so there's no way to modify a .NET class definition to add them. The IronPython engine would have to recognize particular class-level Pythonic annotations and use that information to emit a new CLR class to represent the Python class. It already emits CLR classes as needed to represent Python classes. By "as needed", I mean that a specific CLR base class plus a specific set of CLR interfaces will uniquely determine a class to be emitted by IronPython. This class is cached so that -- once generated -- any new Python class definition that matches this set of (CLR base class plus interfaces) will reuse the same CLR class definition. >> >> What you'd have to change is to put the class-level attributes onto the generated CLR class, then change caching so that the key is (CLR base class plus interfaces plus attributes). It's definitely doable, but raises intriguing questions about "purity". And you'd also need to consider the impact on the larger DLR. >> >> Method-level attributes are an entirely different matter. >> >> On Feb 4, 2008 10:58 AM, Michael Foord wrote: >> >> >> Class decorators will be in Python 2.6 - but there is a big difference >> between a Python runtime decorator and .NET compile time attributes. Is >> it possible to attach attributes at runtime using the reflection API? >> >> Michael >> http://www.manning.com/foord >> >> >> Keith J. Farmer wrote: >> > Can I resurrect this forgotten soul? http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 >> > >> > Having just finished working on LINQ to SQL, I'm convinced that future LINQ providers will be making heavy use of .NET attributes not just on properties, but on classes themselves. Being able to express these attributes in IronPython is a tremendous bonus. That there be one and only one way to express these is paramount. >> > >> > _______________________________________________ >> > Users mailing list >> > Users at lists.ironpython.com >> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> > >> > >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From fuzzyman at voidspace.org.uk Mon Feb 4 23:09:57 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Mon, 04 Feb 2008 22:09:57 +0000 Subject: [IronPython] Decorators on classes In-Reply-To: References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> Message-ID: <47A78D35.7060800@voidspace.org.uk> Keith J. Farmer wrote: > Grandfathering: Giving more consideration to retaining compatibility than it deserves. :) > > Obviously, IronPython should prioritize compatibility with Py2.4, but for obvious reasons I limit that to seeing IP as a consumer of CPy, not the other way around. On the other hand, IP must also be able to consume .NET, and .NET is increasingly making use of things the IP cannot yet express. (I thought of another framework that attributes are used on -- WCF. There are also XML serialization attributes.) > > To that end, I think it would be worthwhile, for the purpose of .NET attributes, to have decorators or their analogues available to IronPython in the current stage of development. That is, I think it should be that IronPython = CPy 2.4 + .NET Attributes + other .NET-isms expressed in a Pythonic way. > Ok - but unless you want *howls* of outrage from the Python community that had better be done in a way compatible with Python syntax. I really like the way the IronPython team chose to add support for typing (e.g. Array[int]) by overloading existing syntax rather than adding new syntax. For the record I think that reusing Python decorators is *fine* as they are at least analogous concepts even if not identical. I *agree* that being able to access attributes is important to IronPython and really want this to happen... The problem is that attributes can be applied to properties, arguments and return values - which don't sit so well with Python decorators. Nesting class decorators to specify the target could work, and they could be applied at parse/compile time rather than runtime. (With the cost that classes with attributes applied are probably not garbage collectable as they mean creating unique CLR classes.) Michael Foord > ________________________________ > > From: users-bounces at lists.ironpython.com on behalf of Michael Foord > Sent: Mon 2/4/2008 11:53 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > > > Keith J. Farmer wrote: > >> I've had no problems with not grandfathering in older APIs, and am quite happy to not grandfather in older syntax, either. >> >> > > What do you mean by 'grandfathering' in this context? > > Michael > > >> I agree that IronPython would have to be able to distinguish between CLR attributes and Python decorators, inasmuch as CLR attributes are a static part of the class/member definition. But I don't think it's an insurmountable problem, and solving it in the DLR, actually, would be very useful. >> >> I wouldn't expect that class authors would want to change the set of .NET attributes frequently if at all -- it doesn't match how they've been designed and how they've evolved, so creating the attributed base class once (and then having pythonic decorators coming in and out at will) seems like a reasonable approach to me. >> >> ________________________________ >> >> From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher >> Sent: Mon 2/4/2008 11:13 AM >> To: Discussion of IronPython >> Subject: Re: [IronPython] Decorators on classes >> >> >> Oh! I didn't realize that about 2.6. >> >> There is indeed a big difference between a Python runtime decorator and a .NET compile time attribute; in fact, the similarities are superficial at best. >> >> .NET attributes are totally static, so there's no way to modify a .NET class definition to add them. The IronPython engine would have to recognize particular class-level Pythonic annotations and use that information to emit a new CLR class to represent the Python class. It already emits CLR classes as needed to represent Python classes. By "as needed", I mean that a specific CLR base class plus a specific set of CLR interfaces will uniquely determine a class to be emitted by IronPython. This class is cached so that -- once generated -- any new Python class definition that matches this set of (CLR base class plus interfaces) will reuse the same CLR class definition. >> >> What you'd have to change is to put the class-level attributes onto the generated CLR class, then change caching so that the key is (CLR base class plus interfaces plus attributes). It's definitely doable, but raises intriguing questions about "purity". And you'd also need to consider the impact on the larger DLR. >> >> Method-level attributes are an entirely different matter. >> >> On Feb 4, 2008 10:58 AM, Michael Foord wrote: >> >> >> Class decorators will be in Python 2.6 - but there is a big difference >> between a Python runtime decorator and .NET compile time attributes. Is >> it possible to attach attributes at runtime using the reflection API? >> >> Michael >> http://www.manning.com/foord >> >> >> Keith J. Farmer wrote: >> > Can I resurrect this forgotten soul? http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 >> > >> > Having just finished working on LINQ to SQL, I'm convinced that future LINQ providers will be making heavy use of .NET attributes not just on properties, but on classes themselves. Being able to express these attributes in IronPython is a tremendous bonus. That there be one and only one way to express these is paramount. >> > >> > _______________________________________________ >> > Users mailing list >> > Users at lists.ironpython.com >> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> > >> > >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From kfarmer at thuban.org Mon Feb 4 23:16:20 2008 From: kfarmer at thuban.org (Keith J. Farmer) Date: Mon, 4 Feb 2008 14:16:20 -0800 Subject: [IronPython] Decorators on classes References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A78B78.4070903@voidspace.org.uk> Message-ID: Python decorators may be sugar, but .NET Attributes are not -- they're metadata that there's no way to emit, currently, without using Reflection API arcana, and no way to append to a type or member that already exists. ________________________________ From: users-bounces at lists.ironpython.com on behalf of Michael Foord Sent: Mon 2/4/2008 2:02 PM To: Discussion of IronPython Subject: Re: [IronPython] Decorators on classes Dino Viehland wrote: > FYI IP 2.0 is tracking 2.5 and we have the big pieces in place plus many small pieces (although there's more to go). In 1.1 we had -X:Python25 which enabled selective 2.5 features and we could conceptually do the same sort of thing for 2.0 so that it includes one or two 2.6 features such as class decorators. > > >From there the decorators to support attributes could even be written in Python. > > Is that right - could attributes be added to an IronPython class (or instances) at runtime using reflection? Earlier parts of this conversation implied that this wasn't the case... Decorators are only syntactic sugar, so the lack of class decorators isn't an impediment... Michael > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Keith J. Farmer > Sent: Monday, February 04, 2008 1:40 PM > To: Discussion of IronPython; Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > Grandfathering: Giving more consideration to retaining compatibility than it deserves. :) > > Obviously, IronPython should prioritize compatibility with Py2.4, but for obvious reasons I limit that to seeing IP as a consumer of CPy, not the other way around. On the other hand, IP must also be able to consume .NET, and .NET is increasingly making use of things the IP cannot yet express. (I thought of another framework that attributes are used on -- WCF. There are also XML serialization attributes.) > > To that end, I think it would be worthwhile, for the purpose of .NET attributes, to have decorators or their analogues available to IronPython in the current stage of development. That is, I think it should be that IronPython = CPy 2.4 + .NET Attributes + other .NET-isms expressed in a Pythonic way. > > ________________________________ > > From: users-bounces at lists.ironpython.com on behalf of Michael Foord > Sent: Mon 2/4/2008 11:53 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > > > Keith J. Farmer wrote: > >> I've had no problems with not grandfathering in older APIs, and am quite happy to not grandfather in older syntax, either. >> >> > > What do you mean by 'grandfathering' in this context? > > Michael > > >> I agree that IronPython would have to be able to distinguish between CLR attributes and Python decorators, inasmuch as CLR attributes are a static part of the class/member definition. But I don't think it's an insurmountable problem, and solving it in the DLR, actually, would be very useful. >> >> I wouldn't expect that class authors would want to change the set of .NET attributes frequently if at all -- it doesn't match how they've been designed and how they've evolved, so creating the attributed base class once (and then having pythonic decorators coming in and out at will) seems like a reasonable approach to me. >> >> ________________________________ >> >> From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher >> Sent: Mon 2/4/2008 11:13 AM >> To: Discussion of IronPython >> Subject: Re: [IronPython] Decorators on classes >> >> >> Oh! I didn't realize that about 2.6. >> >> There is indeed a big difference between a Python runtime decorator and a .NET compile time attribute; in fact, the similarities are superficial at best. >> >> .NET attributes are totally static, so there's no way to modify a .NET class definition to add them. The IronPython engine would have to recognize particular class-level Pythonic annotations and use that information to emit a new CLR class to represent the Python class. It already emits CLR classes as needed to represent Python classes. By "as needed", I mean that a specific CLR base class plus a specific set of CLR interfaces will uniquely determine a class to be emitted by IronPython. This class is cached so that -- once generated -- any new Python class definition that matches this set of (CLR base class plus interfaces) will reuse the same CLR class definition. >> >> What you'd have to change is to put the class-level attributes onto the generated CLR class, then change caching so that the key is (CLR base class plus interfaces plus attributes). It's definitely doable, but raises intriguing questions about "purity". And you'd also need to consider the impact on the larger DLR. >> >> Method-level attributes are an entirely different matter. >> >> On Feb 4, 2008 10:58 AM, Michael Foord wrote: >> >> >> Class decorators will be in Python 2.6 - but there is a big difference >> between a Python runtime decorator and .NET compile time attributes. Is >> it possible to attach attributes at runtime using the reflection API? >> >> Michael >> http://www.manning.com/foord >> >> >> Keith J. Farmer wrote: >> > Can I resurrect this forgotten soul? http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 >> > >> > Having just finished working on LINQ to SQL, I'm convinced that future LINQ providers will be making heavy use of .NET attributes not just on properties, but on classes themselves. Being able to express these attributes in IronPython is a tremendous bonus. That there be one and only one way to express these is paramount. >> > >> > _______________________________________________ >> > Users mailing list >> > Users at lists.ironpython.com >> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> > >> > >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From dinov at exchange.microsoft.com Mon Feb 4 23:27:11 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 4 Feb 2008 14:27:11 -0800 Subject: [IronPython] Decorators on classes In-Reply-To: <47A78B78.4070903@voidspace.org.uk> References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A78B78.4070903@voidspace.org.uk> Message-ID: <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Ok, maybe it's a little optimistic or maybe it needs a couple of hooks exposed, but it's not too crazy. As other people have pointed out decorators are a runtime concept and I don't think we get to change that. So consider a class decorator such as: def ClrAttribute(attr): def attrFunc(class): # do something smart here with attr return attrFunc @ClrAttribute(System.SerializableAttribute) class X(ISomething, object): @ClrAttribute(SomeOtherAttribte) def DoSomething(self): return 42 As Curt mentioned we do a bunch of caching and such with NewTypeMaker and maybe spit out a new type. That's all going to happen before the decorator gets to run - but we'll only create a new type once so there isn't too much overhead here :). >From there you could copy that type w/ Reflection.Emit but add the attribute(s) on it, and then create a new instance of it passing in the PythonType object to its constructor (that's how Python types work - the instance holds onto a copy of the PythonType, the one problem here being that the UnderlyingSystemType of the PythonType would now be wrong, so that might need a hook). This could also include applying the attributes to methods and potentially manifesting concretely typed methods. This same sort of approach might even work w/ a meta-class. Plugging into NewTypeMaker would simplify this but I don't think makes it impossible. There's also other potential problems with systems based up types and attributes: Sometimes they want a type that lives in an assembly and sometimes they want to create instances of types (and they don't know to pass in a PythonType object to the constructor). -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: Monday, February 04, 2008 2:03 PM To: Discussion of IronPython Subject: Re: [IronPython] Decorators on classes Dino Viehland wrote: > FYI IP 2.0 is tracking 2.5 and we have the big pieces in place plus many small pieces (although there's more to go). In 1.1 we had -X:Python25 which enabled selective 2.5 features and we could conceptually do the same sort of thing for 2.0 so that it includes one or two 2.6 features such as class decorators. > > >From there the decorators to support attributes could even be written in Python. > > Is that right - could attributes be added to an IronPython class (or instances) at runtime using reflection? Earlier parts of this conversation implied that this wasn't the case... Decorators are only syntactic sugar, so the lack of class decorators isn't an impediment... Michael > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Keith J. Farmer > Sent: Monday, February 04, 2008 1:40 PM > To: Discussion of IronPython; Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > Grandfathering: Giving more consideration to retaining compatibility than it deserves. :) > > Obviously, IronPython should prioritize compatibility with Py2.4, but for obvious reasons I limit that to seeing IP as a consumer of CPy, not the other way around. On the other hand, IP must also be able to consume .NET, and .NET is increasingly making use of things the IP cannot yet express. (I thought of another framework that attributes are used on -- WCF. There are also XML serialization attributes.) > > To that end, I think it would be worthwhile, for the purpose of .NET attributes, to have decorators or their analogues available to IronPython in the current stage of development. That is, I think it should be that IronPython = CPy 2.4 + .NET Attributes + other .NET-isms expressed in a Pythonic way. > > ________________________________ > > From: users-bounces at lists.ironpython.com on behalf of Michael Foord > Sent: Mon 2/4/2008 11:53 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > > > Keith J. Farmer wrote: > >> I've had no problems with not grandfathering in older APIs, and am quite happy to not grandfather in older syntax, either. >> >> > > What do you mean by 'grandfathering' in this context? > > Michael > > >> I agree that IronPython would have to be able to distinguish between CLR attributes and Python decorators, inasmuch as CLR attributes are a static part of the class/member definition. But I don't think it's an insurmountable problem, and solving it in the DLR, actually, would be very useful. >> >> I wouldn't expect that class authors would want to change the set of .NET attributes frequently if at all -- it doesn't match how they've been designed and how they've evolved, so creating the attributed base class once (and then having pythonic decorators coming in and out at will) seems like a reasonable approach to me. >> >> ________________________________ >> >> From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher >> Sent: Mon 2/4/2008 11:13 AM >> To: Discussion of IronPython >> Subject: Re: [IronPython] Decorators on classes >> >> >> Oh! I didn't realize that about 2.6. >> >> There is indeed a big difference between a Python runtime decorator and a .NET compile time attribute; in fact, the similarities are superficial at best. >> >> .NET attributes are totally static, so there's no way to modify a .NET class definition to add them. The IronPython engine would have to recognize particular class-level Pythonic annotations and use that information to emit a new CLR class to represent the Python class. It already emits CLR classes as needed to represent Python classes. By "as needed", I mean that a specific CLR base class plus a specific set of CLR interfaces will uniquely determine a class to be emitted by IronPython. This class is cached so that -- once generated -- any new Python class definition that matches this set of (CLR base class plus interfaces) will reuse the same CLR class definition. >> >> What you'd have to change is to put the class-level attributes onto the generated CLR class, then change caching so that the key is (CLR base class plus interfaces plus attributes). It's definitely doable, but raises intriguing questions about "purity". And you'd also need to consider the impact on the larger DLR. >> >> Method-level attributes are an entirely different matter. >> >> On Feb 4, 2008 10:58 AM, Michael Foord wrote: >> >> >> Class decorators will be in Python 2.6 - but there is a big difference >> between a Python runtime decorator and .NET compile time attributes. Is >> it possible to attach attributes at runtime using the reflection API? >> >> Michael >> http://www.manning.com/foord >> >> >> Keith J. Farmer wrote: >> > Can I resurrect this forgotten soul? http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 >> > >> > Having just finished working on LINQ to SQL, I'm convinced that future LINQ providers will be making heavy use of .NET attributes not just on properties, but on classes themselves. Being able to express these attributes in IronPython is a tremendous bonus. That there be one and only one way to express these is paramount. >> > >> > _______________________________________________ >> > Users mailing list >> > Users at lists.ironpython.com >> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> > >> > >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From kfarmer at thuban.org Mon Feb 4 23:32:43 2008 From: kfarmer at thuban.org (Keith J. Farmer) Date: Mon, 4 Feb 2008 14:32:43 -0800 Subject: [IronPython] Decorators on classes References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <47A78D35.7060800@voidspace.org.uk> Message-ID: I'm fine with something like @clrAttribute[attributeType]("targetIdentifier", args). I'm interested in the feature more than I am in quibbling over specific syntax. That said, I question the value of syntax compatibility when the API just doesn't exist. When is CPython ever going to run something that depends on the existance of CLR-isms? Adding the support within existing CPy syntax only buys our beloved BDFL the freedom to guide syntax unilaterally. Not a bad thing, mind, and I'm happy to see Guido retain that power, but that's the only practical benefit. CPythonista outrage over not being able to read something they could never run is rather silly. :) ________________________________ From: users-bounces at lists.ironpython.com on behalf of Michael Foord Sent: Mon 2/4/2008 2:09 PM To: Discussion of IronPython Subject: Re: [IronPython] Decorators on classes Keith J. Farmer wrote: > Grandfathering: Giving more consideration to retaining compatibility than it deserves. :) > > Obviously, IronPython should prioritize compatibility with Py2.4, but for obvious reasons I limit that to seeing IP as a consumer of CPy, not the other way around. On the other hand, IP must also be able to consume .NET, and .NET is increasingly making use of things the IP cannot yet express. (I thought of another framework that attributes are used on -- WCF. There are also XML serialization attributes.) > > To that end, I think it would be worthwhile, for the purpose of .NET attributes, to have decorators or their analogues available to IronPython in the current stage of development. That is, I think it should be that IronPython = CPy 2.4 + .NET Attributes + other .NET-isms expressed in a Pythonic way. > Ok - but unless you want *howls* of outrage from the Python community that had better be done in a way compatible with Python syntax. I really like the way the IronPython team chose to add support for typing (e.g. Array[int]) by overloading existing syntax rather than adding new syntax. For the record I think that reusing Python decorators is *fine* as they are at least analogous concepts even if not identical. I *agree* that being able to access attributes is important to IronPython and really want this to happen... The problem is that attributes can be applied to properties, arguments and return values - which don't sit so well with Python decorators. Nesting class decorators to specify the target could work, and they could be applied at parse/compile time rather than runtime. (With the cost that classes with attributes applied are probably not garbage collectable as they mean creating unique CLR classes.) Michael Foord > ________________________________ > > From: users-bounces at lists.ironpython.com on behalf of Michael Foord > Sent: Mon 2/4/2008 11:53 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > > > Keith J. Farmer wrote: > >> I've had no problems with not grandfathering in older APIs, and am quite happy to not grandfather in older syntax, either. >> >> > > What do you mean by 'grandfathering' in this context? > > Michael > > >> I agree that IronPython would have to be able to distinguish between CLR attributes and Python decorators, inasmuch as CLR attributes are a static part of the class/member definition. But I don't think it's an insurmountable problem, and solving it in the DLR, actually, would be very useful. >> >> I wouldn't expect that class authors would want to change the set of .NET attributes frequently if at all -- it doesn't match how they've been designed and how they've evolved, so creating the attributed base class once (and then having pythonic decorators coming in and out at will) seems like a reasonable approach to me. >> >> ________________________________ >> >> From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher >> Sent: Mon 2/4/2008 11:13 AM >> To: Discussion of IronPython >> Subject: Re: [IronPython] Decorators on classes >> >> >> Oh! I didn't realize that about 2.6. >> >> There is indeed a big difference between a Python runtime decorator and a .NET compile time attribute; in fact, the similarities are superficial at best. >> >> .NET attributes are totally static, so there's no way to modify a .NET class definition to add them. The IronPython engine would have to recognize particular class-level Pythonic annotations and use that information to emit a new CLR class to represent the Python class. It already emits CLR classes as needed to represent Python classes. By "as needed", I mean that a specific CLR base class plus a specific set of CLR interfaces will uniquely determine a class to be emitted by IronPython. This class is cached so that -- once generated -- any new Python class definition that matches this set of (CLR base class plus interfaces) will reuse the same CLR class definition. >> >> What you'd have to change is to put the class-level attributes onto the generated CLR class, then change caching so that the key is (CLR base class plus interfaces plus attributes). It's definitely doable, but raises intriguing questions about "purity". And you'd also need to consider the impact on the larger DLR. >> >> Method-level attributes are an entirely different matter. >> >> On Feb 4, 2008 10:58 AM, Michael Foord wrote: >> >> >> Class decorators will be in Python 2.6 - but there is a big difference >> between a Python runtime decorator and .NET compile time attributes. Is >> it possible to attach attributes at runtime using the reflection API? >> >> Michael >> http://www.manning.com/foord >> >> >> Keith J. Farmer wrote: >> > Can I resurrect this forgotten soul? http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 >> > >> > Having just finished working on LINQ to SQL, I'm convinced that future LINQ providers will be making heavy use of .NET attributes not just on properties, but on classes themselves. Being able to express these attributes in IronPython is a tremendous bonus. That there be one and only one way to express these is paramount. >> > >> > _______________________________________________ >> > Users mailing list >> > Users at lists.ironpython.com >> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> > >> > >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From fuzzyman at voidspace.org.uk Mon Feb 4 23:46:01 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Mon, 04 Feb 2008 22:46:01 +0000 Subject: [IronPython] Decorators on classes In-Reply-To: References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <47A78D35.7060800@voidspace.org.uk> Message-ID: <47A795A9.2060201@voidspace.org.uk> Keith J. Farmer wrote: > I'm fine with something like @clrAttribute[attributeType]("targetIdentifier", args). I'm interested in the feature more than I am in quibbling over specific syntax. > > That said, I question the value of syntax compatibility when the API just doesn't exist. When is CPython ever going to run something that depends on the existance of CLR-isms? Adding the support within existing CPy syntax only buys our beloved BDFL the freedom to guide syntax unilaterally. Not a bad thing, mind, and I'm happy to see Guido retain that power, but that's the only practical benefit. > > CPythonista outrage over not being able to read something they could never run is rather silly. :) > I would see it as more of a concern that IronPython is no longer a faithful implementation of Python but a hybrid language that is mostly Python and partly something of Microsoft's invention. Python has been evolved gradually and gracefully under the hands of Guido, the core developers and the community. Microsoft has no place introducing incompatible syntax and wanting the community to still think of it as Python. I'm sure the IronPython team are aware of this. :-) Michael http://www.manning.com/foord > ________________________________ > > From: users-bounces at lists.ironpython.com on behalf of Michael Foord > Sent: Mon 2/4/2008 2:09 PM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > > > Keith J. Farmer wrote: > >> Grandfathering: Giving more consideration to retaining compatibility than it deserves. :) >> >> Obviously, IronPython should prioritize compatibility with Py2.4, but for obvious reasons I limit that to seeing IP as a consumer of CPy, not the other way around. On the other hand, IP must also be able to consume .NET, and .NET is increasingly making use of things the IP cannot yet express. (I thought of another framework that attributes are used on -- WCF. There are also XML serialization attributes.) >> >> To that end, I think it would be worthwhile, for the purpose of .NET attributes, to have decorators or their analogues available to IronPython in the current stage of development. That is, I think it should be that IronPython = CPy 2.4 + .NET Attributes + other .NET-isms expressed in a Pythonic way. >> >> > > Ok - but unless you want *howls* of outrage from the Python community > that had better be done in a way compatible with Python syntax. I really > like the way the IronPython team chose to add support for typing (e.g. > Array[int]) by overloading existing syntax rather than adding new syntax. > > For the record I think that reusing Python decorators is *fine* as they > are at least analogous concepts even if not identical. > > I *agree* that being able to access attributes is important to > IronPython and really want this to happen... > > The problem is that attributes can be applied to properties, arguments > and return values - which don't sit so well with Python decorators. > Nesting class decorators to specify the target could work, and they > could be applied at parse/compile time rather than runtime. (With the > cost that classes with attributes applied are probably not garbage > collectable as they mean creating unique CLR classes.) > > Michael Foord > > >> ________________________________ >> >> From: users-bounces at lists.ironpython.com on behalf of Michael Foord >> Sent: Mon 2/4/2008 11:53 AM >> To: Discussion of IronPython >> Subject: Re: [IronPython] Decorators on classes >> >> >> >> Keith J. Farmer wrote: >> >> >>> I've had no problems with not grandfathering in older APIs, and am quite happy to not grandfather in older syntax, either. >>> >>> >>> >> What do you mean by 'grandfathering' in this context? >> >> Michael >> >> >> >>> I agree that IronPython would have to be able to distinguish between CLR attributes and Python decorators, inasmuch as CLR attributes are a static part of the class/member definition. But I don't think it's an insurmountable problem, and solving it in the DLR, actually, would be very useful. >>> >>> I wouldn't expect that class authors would want to change the set of .NET attributes frequently if at all -- it doesn't match how they've been designed and how they've evolved, so creating the attributed base class once (and then having pythonic decorators coming in and out at will) seems like a reasonable approach to me. >>> >>> ________________________________ >>> >>> From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher >>> Sent: Mon 2/4/2008 11:13 AM >>> To: Discussion of IronPython >>> Subject: Re: [IronPython] Decorators on classes >>> >>> >>> Oh! I didn't realize that about 2.6. >>> >>> There is indeed a big difference between a Python runtime decorator and a .NET compile time attribute; in fact, the similarities are superficial at best. >>> >>> .NET attributes are totally static, so there's no way to modify a .NET class definition to add them. The IronPython engine would have to recognize particular class-level Pythonic annotations and use that information to emit a new CLR class to represent the Python class. It already emits CLR classes as needed to represent Python classes. By "as needed", I mean that a specific CLR base class plus a specific set of CLR interfaces will uniquely determine a class to be emitted by IronPython. This class is cached so that -- once generated -- any new Python class definition that matches this set of (CLR base class plus interfaces) will reuse the same CLR class definition. >>> >>> What you'd have to change is to put the class-level attributes onto the generated CLR class, then change caching so that the key is (CLR base class plus interfaces plus attributes). It's definitely doable, but raises intriguing questions about "purity". And you'd also need to consider the impact on the larger DLR. >>> >>> Method-level attributes are an entirely different matter. >>> >>> On Feb 4, 2008 10:58 AM, Michael Foord wrote: >>> >>> >>> Class decorators will be in Python 2.6 - but there is a big difference >>> between a Python runtime decorator and .NET compile time attributes. Is >>> it possible to attach attributes at runtime using the reflection API? >>> >>> Michael >>> http://www.manning.com/foord >>> >>> >>> Keith J. Farmer wrote: >>> > Can I resurrect this forgotten soul? http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 >>> > >>> > Having just finished working on LINQ to SQL, I'm convinced that future LINQ providers will be making heavy use of .NET attributes not just on properties, but on classes themselves. Being able to express these attributes in IronPython is a tremendous bonus. That there be one and only one way to express these is paramount. >>> > >>> > _______________________________________________ >>> > Users mailing list >>> > Users at lists.ironpython.com >>> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> > >>> > >>> >>> _______________________________________________ >>> Users mailing list >>> Users at lists.ironpython.com >>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> >>> >>> >>> _______________________________________________ >>> Users mailing list >>> Users at lists.ironpython.com >>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> >>> >>> >>> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From curt at hagenlocher.org Mon Feb 4 23:54:27 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Mon, 4 Feb 2008 14:54:27 -0800 Subject: [IronPython] Decorators on classes In-Reply-To: <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A78B78.4070903@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: On Feb 4, 2008 2:27 PM, Dino Viehland wrote: > > As other people have pointed out decorators are a runtime concept and I > don't think we get to change that. So consider a class decorator You could theoretically have a "slightly alternate" parsing mode that recognizes a specific class decorator name before the class definition is closed (and therefore before codegen). In other words, the following definition > @ClrAttribute(System.SerializableAttribute) > class X(ISomething, object): treats the decorator differently if it matches one of the special-case names. The change in parsing could be triggered by something like "from future import clr_hacks". On Feb 4, 2008 2:32 PM, Keith J. Farmer wrote: > > CPythonista outrage over not being able to read something they could > never run is rather silly. :) You're clearly having trouble envisioning the following Slashdot headline: "Microsoft inflicts 'embrace and extend' on Python". Silly or not, perceptions are hugely important. -- Curt Hagenlocher curt at hagenlocher.org From fuzzyman at voidspace.org.uk Mon Feb 4 23:54:53 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Mon, 04 Feb 2008 22:54:53 +0000 Subject: [IronPython] Decorators on classes In-Reply-To: <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A78B78.4070903@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <47A797BD.7010906@voidspace.org.uk> Hello Dino, That sounds *great*, and is something really needed by IronPython. How long do you think it will take you to implement? <0.5 wink> Michael http://www.manning.com/foord Dino Viehland wrote: > Ok, maybe it's a little optimistic or maybe it needs a couple of hooks exposed, but it's not too crazy. > > As other people have pointed out decorators are a runtime concept and I don't think we get to change that. So consider a class decorator such as: > > def ClrAttribute(attr): > def attrFunc(class): > # do something smart here with attr > return attrFunc > > @ClrAttribute(System.SerializableAttribute) > class X(ISomething, object): > @ClrAttribute(SomeOtherAttribte) > def DoSomething(self): > return 42 > > > As Curt mentioned we do a bunch of caching and such with NewTypeMaker and maybe spit out a new type. That's all going to happen before the decorator gets to run - but we'll only create a new type once so there isn't too much overhead here :). > > >From there you could copy that type w/ Reflection.Emit but add the attribute(s) on it, and then create a new instance of it passing in the PythonType object to its constructor (that's how Python types work - the instance holds onto a copy of the PythonType, the one problem here being that the UnderlyingSystemType of the PythonType would now be wrong, so that might need a hook). This could also include applying the attributes to methods and potentially manifesting concretely typed methods. This same sort of approach might even work w/ a meta-class. > > Plugging into NewTypeMaker would simplify this but I don't think makes it impossible. > > There's also other potential problems with systems based up types and attributes: Sometimes they want a type that lives in an assembly and sometimes they want to create instances of types (and they don't know to pass in a PythonType object to the constructor). > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord > Sent: Monday, February 04, 2008 2:03 PM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > Dino Viehland wrote: > >> FYI IP 2.0 is tracking 2.5 and we have the big pieces in place plus many small pieces (although there's more to go). In 1.1 we had -X:Python25 which enabled selective 2.5 features and we could conceptually do the same sort of thing for 2.0 so that it includes one or two 2.6 features such as class decorators. >> >> >From there the decorators to support attributes could even be written in Python. >> >> >> > > Is that right - could attributes be added to an IronPython class (or > instances) at runtime using reflection? Earlier parts of this > conversation implied that this wasn't the case... > > Decorators are only syntactic sugar, so the lack of class decorators > isn't an impediment... > > Michael > > > >> -----Original Message----- >> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Keith J. Farmer >> Sent: Monday, February 04, 2008 1:40 PM >> To: Discussion of IronPython; Discussion of IronPython >> Subject: Re: [IronPython] Decorators on classes >> >> Grandfathering: Giving more consideration to retaining compatibility than it deserves. :) >> >> Obviously, IronPython should prioritize compatibility with Py2.4, but for obvious reasons I limit that to seeing IP as a consumer of CPy, not the other way around. On the other hand, IP must also be able to consume .NET, and .NET is increasingly making use of things the IP cannot yet express. (I thought of another framework that attributes are used on -- WCF. There are also XML serialization attributes.) >> >> To that end, I think it would be worthwhile, for the purpose of .NET attributes, to have decorators or their analogues available to IronPython in the current stage of development. That is, I think it should be that IronPython = CPy 2.4 + .NET Attributes + other .NET-isms expressed in a Pythonic way. >> >> ________________________________ >> >> From: users-bounces at lists.ironpython.com on behalf of Michael Foord >> Sent: Mon 2/4/2008 11:53 AM >> To: Discussion of IronPython >> Subject: Re: [IronPython] Decorators on classes >> >> >> >> Keith J. Farmer wrote: >> >> >>> I've had no problems with not grandfathering in older APIs, and am quite happy to not grandfather in older syntax, either. >>> >>> >>> >> What do you mean by 'grandfathering' in this context? >> >> Michael >> >> >> >>> I agree that IronPython would have to be able to distinguish between CLR attributes and Python decorators, inasmuch as CLR attributes are a static part of the class/member definition. But I don't think it's an insurmountable problem, and solving it in the DLR, actually, would be very useful. >>> >>> I wouldn't expect that class authors would want to change the set of .NET attributes frequently if at all -- it doesn't match how they've been designed and how they've evolved, so creating the attributed base class once (and then having pythonic decorators coming in and out at will) seems like a reasonable approach to me. >>> >>> ________________________________ >>> >>> From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher >>> Sent: Mon 2/4/2008 11:13 AM >>> To: Discussion of IronPython >>> Subject: Re: [IronPython] Decorators on classes >>> >>> >>> Oh! I didn't realize that about 2.6. >>> >>> There is indeed a big difference between a Python runtime decorator and a .NET compile time attribute; in fact, the similarities are superficial at best. >>> >>> .NET attributes are totally static, so there's no way to modify a .NET class definition to add them. The IronPython engine would have to recognize particular class-level Pythonic annotations and use that information to emit a new CLR class to represent the Python class. It already emits CLR classes as needed to represent Python classes. By "as needed", I mean that a specific CLR base class plus a specific set of CLR interfaces will uniquely determine a class to be emitted by IronPython. This class is cached so that -- once generated -- any new Python class definition that matches this set of (CLR base class plus interfaces) will reuse the same CLR class definition. >>> >>> What you'd have to change is to put the class-level attributes onto the generated CLR class, then change caching so that the key is (CLR base class plus interfaces plus attributes). It's definitely doable, but raises intriguing questions about "purity". And you'd also need to consider the impact on the larger DLR. >>> >>> Method-level attributes are an entirely different matter. >>> >>> On Feb 4, 2008 10:58 AM, Michael Foord wrote: >>> >>> >>> Class decorators will be in Python 2.6 - but there is a big difference >>> between a Python runtime decorator and .NET compile time attributes. Is >>> it possible to attach attributes at runtime using the reflection API? >>> >>> Michael >>> http://www.manning.com/foord >>> >>> >>> Keith J. Farmer wrote: >>> > Can I resurrect this forgotten soul? http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 >>> > >>> > Having just finished working on LINQ to SQL, I'm convinced that future LINQ providers will be making heavy use of .NET attributes not just on properties, but on classes themselves. Being able to express these attributes in IronPython is a tremendous bonus. That there be one and only one way to express these is paramount. >>> > >>> > _______________________________________________ >>> > Users mailing list >>> > Users at lists.ironpython.com >>> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> > >>> > >>> >>> _______________________________________________ >>> Users mailing list >>> Users at lists.ironpython.com >>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> >>> >>> >>> _______________________________________________ >>> Users mailing list >>> Users at lists.ironpython.com >>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> >>> >>> >>> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From curt at hagenlocher.org Tue Feb 5 00:01:04 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Mon, 4 Feb 2008 15:01:04 -0800 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: <47A76257.6090307@voidspace.org.uk> References: <47A75FA4.5090308@voidspace.org.uk> <47A76257.6090307@voidspace.org.uk> Message-ID: On Feb 4, 2008 11:07 AM, Michael Foord wrote: > >Curt Hagenlocher wrote: >> The assemblies call into the IronPython engine (version 2) to load and >> execute the script. Currently, the script is loaded from the file >> system, but I'd eventually like to support embedding any >> required scripts as resources in the assembly, so that the whole thing >> can be distributed as a single neat package. > > Great - you beat me to it. :-) > > If you make this open source then I'll be happy to help on it. I'm thinking of putting it on Codeplex. Be warned that I prefer ILGenerator to CodeDOM, probably because I'm reliving the glory years of assembly language programming. "6502 4eva!" :) The current implementation is written in Python. -- Curt Hagenlocher curt at hagenlocher.org From fuzzyman at voidspace.org.uk Tue Feb 5 00:05:30 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Mon, 04 Feb 2008 23:05:30 +0000 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: References: <47A75FA4.5090308@voidspace.org.uk> <47A76257.6090307@voidspace.org.uk> Message-ID: <47A79A3A.8070002@voidspace.org.uk> Curt Hagenlocher wrote: > On Feb 4, 2008 11:07 AM, Michael Foord wrote: > >> Curt Hagenlocher wrote: >> >>> The assemblies call into the IronPython engine (version 2) to load and >>> execute the script. Currently, the script is loaded from the file >>> system, but I'd eventually like to support embedding any >>> required scripts as resources in the assembly, so that the whole thing >>> can be distributed as a single neat package. >>> >> Great - you beat me to it. :-) >> >> If you make this open source then I'll be happy to help on it. >> > > I'm thinking of putting it on Codeplex. Be warned that I prefer ILGenerator to > CodeDOM, probably because I'm reliving the glory years of assembly language > programming. "6502 4eva!" :) > Ouch. :-) Although in my case it was 68000 forever (truly beautiful CPU - based appreciated inside an Amiga). I'd love to learn more about generating IL - although it does make the learning curve steeper (I have tinkered but nothing more). > The current implementation is written in Python. > I would recommend leaving it in Python unless you have compelling reasons to rewrite... I'm sure you will - but when you get it up on CodeDOM post an announcement here so that I can blog about it. This is great news as it fills one 'missing piece of the puzzle' when it comes to integrating IronPython with other .NET languages. Michael > -- > Curt Hagenlocher > curt at hagenlocher.org > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From curt at hagenlocher.org Tue Feb 5 00:17:54 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Mon, 4 Feb 2008 15:17:54 -0800 Subject: [IronPython] Decorators on classes In-Reply-To: <47A797BD.7010906@voidspace.org.uk> References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A78B78.4070903@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A797BD.7010906@voidspace.org.uk> Message-ID: Here's an implementation idea that may require less work at the expense of less-elegant syntax. class X(object, clr.AttributeBase(System.SerializableAttribute)) pass NewTypeMaker would look for base classes of whatever built-in type is returned by clr.AttributeBase and would use that information to decorate the generated type. -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From kfarmer at thuban.org Tue Feb 5 00:27:02 2008 From: kfarmer at thuban.org (Keith J. Farmer) Date: Mon, 4 Feb 2008 15:27:02 -0800 Subject: [IronPython] Decorators on classes References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <47A78D35.7060800@voidspace.org.uk> <47A795A9.2060201@voidspace.org.uk> Message-ID: If I can come to terms with Peter Jackson's portrayal of LotR... I said it was silly. I didn't say the reasons didn't exist. ________________________________ From: users-bounces at lists.ironpython.com on behalf of Michael Foord Sent: Mon 2/4/2008 2:46 PM To: Discussion of IronPython Subject: Re: [IronPython] Decorators on classes Keith J. Farmer wrote: > I'm fine with something like @clrAttribute[attributeType]("targetIdentifier", args). I'm interested in the feature more than I am in quibbling over specific syntax. > > That said, I question the value of syntax compatibility when the API just doesn't exist. When is CPython ever going to run something that depends on the existance of CLR-isms? Adding the support within existing CPy syntax only buys our beloved BDFL the freedom to guide syntax unilaterally. Not a bad thing, mind, and I'm happy to see Guido retain that power, but that's the only practical benefit. > > CPythonista outrage over not being able to read something they could never run is rather silly. :) > I would see it as more of a concern that IronPython is no longer a faithful implementation of Python but a hybrid language that is mostly Python and partly something of Microsoft's invention. Python has been evolved gradually and gracefully under the hands of Guido, the core developers and the community. Microsoft has no place introducing incompatible syntax and wanting the community to still think of it as Python. I'm sure the IronPython team are aware of this. :-) Michael http://www.manning.com/foord > ________________________________ > > From: users-bounces at lists.ironpython.com on behalf of Michael Foord > Sent: Mon 2/4/2008 2:09 PM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > > > Keith J. Farmer wrote: > >> Grandfathering: Giving more consideration to retaining compatibility than it deserves. :) >> >> Obviously, IronPython should prioritize compatibility with Py2.4, but for obvious reasons I limit that to seeing IP as a consumer of CPy, not the other way around. On the other hand, IP must also be able to consume .NET, and .NET is increasingly making use of things the IP cannot yet express. (I thought of another framework that attributes are used on -- WCF. There are also XML serialization attributes.) >> >> To that end, I think it would be worthwhile, for the purpose of .NET attributes, to have decorators or their analogues available to IronPython in the current stage of development. That is, I think it should be that IronPython = CPy 2.4 + .NET Attributes + other .NET-isms expressed in a Pythonic way. >> >> > > Ok - but unless you want *howls* of outrage from the Python community > that had better be done in a way compatible with Python syntax. I really > like the way the IronPython team chose to add support for typing (e.g. > Array[int]) by overloading existing syntax rather than adding new syntax. > > For the record I think that reusing Python decorators is *fine* as they > are at least analogous concepts even if not identical. > > I *agree* that being able to access attributes is important to > IronPython and really want this to happen... > > The problem is that attributes can be applied to properties, arguments > and return values - which don't sit so well with Python decorators. > Nesting class decorators to specify the target could work, and they > could be applied at parse/compile time rather than runtime. (With the > cost that classes with attributes applied are probably not garbage > collectable as they mean creating unique CLR classes.) > > Michael Foord > > >> ________________________________ >> >> From: users-bounces at lists.ironpython.com on behalf of Michael Foord >> Sent: Mon 2/4/2008 11:53 AM >> To: Discussion of IronPython >> Subject: Re: [IronPython] Decorators on classes >> >> >> >> Keith J. Farmer wrote: >> >> >>> I've had no problems with not grandfathering in older APIs, and am quite happy to not grandfather in older syntax, either. >>> >>> >>> >> What do you mean by 'grandfathering' in this context? >> >> Michael >> >> >> >>> I agree that IronPython would have to be able to distinguish between CLR attributes and Python decorators, inasmuch as CLR attributes are a static part of the class/member definition. But I don't think it's an insurmountable problem, and solving it in the DLR, actually, would be very useful. >>> >>> I wouldn't expect that class authors would want to change the set of .NET attributes frequently if at all -- it doesn't match how they've been designed and how they've evolved, so creating the attributed base class once (and then having pythonic decorators coming in and out at will) seems like a reasonable approach to me. >>> >>> ________________________________ >>> >>> From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher >>> Sent: Mon 2/4/2008 11:13 AM >>> To: Discussion of IronPython >>> Subject: Re: [IronPython] Decorators on classes >>> >>> >>> Oh! I didn't realize that about 2.6. >>> >>> There is indeed a big difference between a Python runtime decorator and a .NET compile time attribute; in fact, the similarities are superficial at best. >>> >>> .NET attributes are totally static, so there's no way to modify a .NET class definition to add them. The IronPython engine would have to recognize particular class-level Pythonic annotations and use that information to emit a new CLR class to represent the Python class. It already emits CLR classes as needed to represent Python classes. By "as needed", I mean that a specific CLR base class plus a specific set of CLR interfaces will uniquely determine a class to be emitted by IronPython. This class is cached so that -- once generated -- any new Python class definition that matches this set of (CLR base class plus interfaces) will reuse the same CLR class definition. >>> >>> What you'd have to change is to put the class-level attributes onto the generated CLR class, then change caching so that the key is (CLR base class plus interfaces plus attributes). It's definitely doable, but raises intriguing questions about "purity". And you'd also need to consider the impact on the larger DLR. >>> >>> Method-level attributes are an entirely different matter. >>> >>> On Feb 4, 2008 10:58 AM, Michael Foord wrote: >>> >>> >>> Class decorators will be in Python 2.6 - but there is a big difference >>> between a Python runtime decorator and .NET compile time attributes. Is >>> it possible to attach attributes at runtime using the reflection API? >>> >>> Michael >>> http://www.manning.com/foord >>> >>> >>> Keith J. Farmer wrote: >>> > Can I resurrect this forgotten soul? http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 >>> > >>> > Having just finished working on LINQ to SQL, I'm convinced that future LINQ providers will be making heavy use of .NET attributes not just on properties, but on classes themselves. Being able to express these attributes in IronPython is a tremendous bonus. That there be one and only one way to express these is paramount. >>> > >>> > _______________________________________________ >>> > Users mailing list >>> > Users at lists.ironpython.com >>> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> > >>> > >>> >>> _______________________________________________ >>> Users mailing list >>> Users at lists.ironpython.com >>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> >>> >>> >>> _______________________________________________ >>> Users mailing list >>> Users at lists.ironpython.com >>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> >>> >>> >>> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From kfarmer at thuban.org Tue Feb 5 00:28:54 2008 From: kfarmer at thuban.org (Keith J. Farmer) Date: Mon, 4 Feb 2008 15:28:54 -0800 Subject: [IronPython] Decorators on classes References: <47A7603D.8040102@voidspace.org.uk><47A76D2D.2040500@voidspace.org.uk><7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com><47A78B78.4070903@voidspace.org.uk><7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com><47A797BD.7010906@voidspace.org.uk> Message-ID: We would need this to apply to what would be CLR properties, fields, and methods. ________________________________ From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher Sent: Mon 2/4/2008 3:17 PM To: Discussion of IronPython Subject: Re: [IronPython] Decorators on classes Here's an implementation idea that may require less work at the expense of less-elegant syntax. class X(object, clr.AttributeBase(System.SerializableAttribute)) pass NewTypeMaker would look for base classes of whatever built-in type is returned by clr.AttributeBase and would use that information to decorate the generated type. -- Curt Hagenlocher curt at hagenlocher.org From fuzzyman at voidspace.org.uk Tue Feb 5 00:29:42 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Mon, 04 Feb 2008 23:29:42 +0000 Subject: [IronPython] Decorators on classes In-Reply-To: References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A78B78.4070903@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A797BD.7010906@voidspace.org.uk> Message-ID: <47A79FE6.4050606@voidspace.org.uk> Curt Hagenlocher wrote: > Here's an implementation idea that may require less work at the > expense of less-elegant syntax. > > class X(object, clr.AttributeBase(System.SerializableAttribute)) > pass > > NewTypeMaker would look for base classes of whatever built-in type is > returned by clr.AttributeBase and would use that information to > decorate the generated type. > That wouldn't play well with metaclasses, which isn't a showstopper. It is rather ugly. :-) Would this technique have anything to offer for attributes on methods and properties (etc). Michael > -- > Curt Hagenlocher > curt at hagenlocher.org > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From kfarmer at thuban.org Tue Feb 5 00:29:48 2008 From: kfarmer at thuban.org (Keith J. Farmer) Date: Mon, 4 Feb 2008 15:29:48 -0800 Subject: [IronPython] Decorators on classes References: <47A7603D.8040102@voidspace.org.uk><47A76D2D.2040500@voidspace.org.uk><7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com><47A78B78.4070903@voidspace.org.uk><7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: On the contrary, I have no problem whatsoever envisioning any outrageous headline on Slashdot, regardless of the actual facts. I left that crowd many years ago. ________________________________ From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher Sent: Mon 2/4/2008 2:54 PM To: Discussion of IronPython Subject: Re: [IronPython] Decorators on classes On Feb 4, 2008 2:32 PM, Keith J. Farmer wrote: > > CPythonista outrage over not being able to read something they could > never run is rather silly. :) You're clearly having trouble envisioning the following Slashdot headline: "Microsoft inflicts 'embrace and extend' on Python". Silly or not, perceptions are hugely important. From curt at hagenlocher.org Tue Feb 5 00:46:39 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Mon, 4 Feb 2008 15:46:39 -0800 Subject: [IronPython] Decorators on classes In-Reply-To: <47A79FE6.4050606@voidspace.org.uk> References: <47A76D2D.2040500@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A78B78.4070903@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A797BD.7010906@voidspace.org.uk> <47A79FE6.4050606@voidspace.org.uk> Message-ID: On Feb 4, 2008 3:29 PM, Michael Foord wrote: > > It is rather ugly. :-) Thanks; I thought so myself. > Would this technique have anything to offer for attributes on methods > and properties (etc). It's hard to see how, but it's been a while since I looked at that part of the source. I'm pretty sure that the CLR class itself needs to be emitted entirely by the contents of the one "class" statement -- and well before the first method is defined. Which means that none of the properties or methods of the class could influence codegen. Frankly, I don't think that attributes on methods or properties are realistic -- at least, not as part of the original class definition. What I think you'd be looking at is the ability to define a class wrapper that wraps the initially-defined dynamic class with a new statically-defined class that allows you to put attributes on methods and properties. Hmm... where have I heard that recently... :) -- Curt Hagenlocher curt at hagenlocher.org From dinov at exchange.microsoft.com Tue Feb 5 00:54:49 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 4 Feb 2008 15:54:49 -0800 Subject: [IronPython] Decorators on classes In-Reply-To: <47A797BD.7010906@voidspace.org.uk> References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A78B78.4070903@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A797BD.7010906@voidspace.org.uk> Message-ID: <7AD436E4270DD54A94238001769C2227011CF47C8F4F@DF-GRTDANE-MSG.exchange.corp.microsoft.com> This might be something fun to look at during the sprints at PyCon. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: Monday, February 04, 2008 2:55 PM To: Discussion of IronPython Subject: Re: [IronPython] Decorators on classes Hello Dino, That sounds *great*, and is something really needed by IronPython. How long do you think it will take you to implement? <0.5 wink> Michael http://www.manning.com/foord Dino Viehland wrote: > Ok, maybe it's a little optimistic or maybe it needs a couple of hooks exposed, but it's not too crazy. > > As other people have pointed out decorators are a runtime concept and I don't think we get to change that. So consider a class decorator such as: > > def ClrAttribute(attr): > def attrFunc(class): > # do something smart here with attr > return attrFunc > > @ClrAttribute(System.SerializableAttribute) > class X(ISomething, object): > @ClrAttribute(SomeOtherAttribte) > def DoSomething(self): > return 42 > > > As Curt mentioned we do a bunch of caching and such with NewTypeMaker and maybe spit out a new type. That's all going to happen before the decorator gets to run - but we'll only create a new type once so there isn't too much overhead here :). > > >From there you could copy that type w/ Reflection.Emit but add the attribute(s) on it, and then create a new instance of it passing in the PythonType object to its constructor (that's how Python types work - the instance holds onto a copy of the PythonType, the one problem here being that the UnderlyingSystemType of the PythonType would now be wrong, so that might need a hook). This could also include applying the attributes to methods and potentially manifesting concretely typed methods. This same sort of approach might even work w/ a meta-class. > > Plugging into NewTypeMaker would simplify this but I don't think makes it impossible. > > There's also other potential problems with systems based up types and attributes: Sometimes they want a type that lives in an assembly and sometimes they want to create instances of types (and they don't know to pass in a PythonType object to the constructor). > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord > Sent: Monday, February 04, 2008 2:03 PM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > Dino Viehland wrote: > >> FYI IP 2.0 is tracking 2.5 and we have the big pieces in place plus many small pieces (although there's more to go). In 1.1 we had -X:Python25 which enabled selective 2.5 features and we could conceptually do the same sort of thing for 2.0 so that it includes one or two 2.6 features such as class decorators. >> >> >From there the decorators to support attributes could even be written in Python. >> >> >> > > Is that right - could attributes be added to an IronPython class (or > instances) at runtime using reflection? Earlier parts of this > conversation implied that this wasn't the case... > > Decorators are only syntactic sugar, so the lack of class decorators > isn't an impediment... > > Michael > > > >> -----Original Message----- >> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Keith J. Farmer >> Sent: Monday, February 04, 2008 1:40 PM >> To: Discussion of IronPython; Discussion of IronPython >> Subject: Re: [IronPython] Decorators on classes >> >> Grandfathering: Giving more consideration to retaining compatibility than it deserves. :) >> >> Obviously, IronPython should prioritize compatibility with Py2.4, but for obvious reasons I limit that to seeing IP as a consumer of CPy, not the other way around. On the other hand, IP must also be able to consume .NET, and .NET is increasingly making use of things the IP cannot yet express. (I thought of another framework that attributes are used on -- WCF. There are also XML serialization attributes.) >> >> To that end, I think it would be worthwhile, for the purpose of .NET attributes, to have decorators or their analogues available to IronPython in the current stage of development. That is, I think it should be that IronPython = CPy 2.4 + .NET Attributes + other .NET-isms expressed in a Pythonic way. >> >> ________________________________ >> >> From: users-bounces at lists.ironpython.com on behalf of Michael Foord >> Sent: Mon 2/4/2008 11:53 AM >> To: Discussion of IronPython >> Subject: Re: [IronPython] Decorators on classes >> >> >> >> Keith J. Farmer wrote: >> >> >>> I've had no problems with not grandfathering in older APIs, and am quite happy to not grandfather in older syntax, either. >>> >>> >>> >> What do you mean by 'grandfathering' in this context? >> >> Michael >> >> >> >>> I agree that IronPython would have to be able to distinguish between CLR attributes and Python decorators, inasmuch as CLR attributes are a static part of the class/member definition. But I don't think it's an insurmountable problem, and solving it in the DLR, actually, would be very useful. >>> >>> I wouldn't expect that class authors would want to change the set of .NET attributes frequently if at all -- it doesn't match how they've been designed and how they've evolved, so creating the attributed base class once (and then having pythonic decorators coming in and out at will) seems like a reasonable approach to me. >>> >>> ________________________________ >>> >>> From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher >>> Sent: Mon 2/4/2008 11:13 AM >>> To: Discussion of IronPython >>> Subject: Re: [IronPython] Decorators on classes >>> >>> >>> Oh! I didn't realize that about 2.6. >>> >>> There is indeed a big difference between a Python runtime decorator and a .NET compile time attribute; in fact, the similarities are superficial at best. >>> >>> .NET attributes are totally static, so there's no way to modify a .NET class definition to add them. The IronPython engine would have to recognize particular class-level Pythonic annotations and use that information to emit a new CLR class to represent the Python class. It already emits CLR classes as needed to represent Python classes. By "as needed", I mean that a specific CLR base class plus a specific set of CLR interfaces will uniquely determine a class to be emitted by IronPython. This class is cached so that -- once generated -- any new Python class definition that matches this set of (CLR base class plus interfaces) will reuse the same CLR class definition. >>> >>> What you'd have to change is to put the class-level attributes onto the generated CLR class, then change caching so that the key is (CLR base class plus interfaces plus attributes). It's definitely doable, but raises intriguing questions about "purity". And you'd also need to consider the impact on the larger DLR. >>> >>> Method-level attributes are an entirely different matter. >>> >>> On Feb 4, 2008 10:58 AM, Michael Foord wrote: >>> >>> >>> Class decorators will be in Python 2.6 - but there is a big difference >>> between a Python runtime decorator and .NET compile time attributes. Is >>> it possible to attach attributes at runtime using the reflection API? >>> >>> Michael >>> http://www.manning.com/foord >>> >>> >>> Keith J. Farmer wrote: >>> > Can I resurrect this forgotten soul? http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 >>> > >>> > Having just finished working on LINQ to SQL, I'm convinced that future LINQ providers will be making heavy use of .NET attributes not just on properties, but on classes themselves. Being able to express these attributes in IronPython is a tremendous bonus. That there be one and only one way to express these is paramount. >>> > >>> > _______________________________________________ >>> > Users mailing list >>> > Users at lists.ironpython.com >>> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> > >>> > >>> >>> _______________________________________________ >>> Users mailing list >>> Users at lists.ironpython.com >>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> >>> >>> >>> _______________________________________________ >>> Users mailing list >>> Users at lists.ironpython.com >>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> >>> >>> >>> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From dinov at exchange.microsoft.com Tue Feb 5 00:59:54 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 4 Feb 2008 15:59:54 -0800 Subject: [IronPython] Decorators on classes In-Reply-To: References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A78B78.4070903@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF47C8F53@DF-GRTDANE-MSG.exchange.corp.microsoft.com> from future import clr_hacks sounds like the start of an awfully slippery slope. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Monday, February 04, 2008 2:54 PM To: Discussion of IronPython Subject: Re: [IronPython] Decorators on classes On Feb 4, 2008 2:27 PM, Dino Viehland wrote: > > As other people have pointed out decorators are a runtime concept and I > don't think we get to change that. So consider a class decorator You could theoretically have a "slightly alternate" parsing mode that recognizes a specific class decorator name before the class definition is closed (and therefore before codegen). In other words, the following definition > @ClrAttribute(System.SerializableAttribute) > class X(ISomething, object): treats the decorator differently if it matches one of the special-case names. The change in parsing could be triggered by something like "from future import clr_hacks". On Feb 4, 2008 2:32 PM, Keith J. Farmer wrote: > > CPythonista outrage over not being able to read something they could > never run is rather silly. :) You're clearly having trouble envisioning the following Slashdot headline: "Microsoft inflicts 'embrace and extend' on Python". Silly or not, perceptions are hugely important. -- Curt Hagenlocher curt at hagenlocher.org _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From fuzzyman at voidspace.org.uk Tue Feb 5 01:07:57 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Tue, 05 Feb 2008 00:07:57 +0000 Subject: [IronPython] Decorators on classes In-Reply-To: References: <47A76D2D.2040500@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A78B78.4070903@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A797BD.7010906@voidspace.org.uk> <47A79FE6.4050606@voidspace.org.uk> Message-ID: <47A7A8DD.1040307@voidspace.org.uk> Curt Hagenlocher wrote: > On Feb 4, 2008 3:29 PM, Michael Foord wrote: > >> It is rather ugly. :-) >> > > Thanks; I thought so myself. > > >> Would this technique have anything to offer for attributes on methods >> and properties (etc). >> > > It's hard to see how, but it's been a while since I looked at that > part of the source. I'm pretty sure that the CLR class itself needs > to be emitted entirely by the contents of the one "class" statement -- > and well before the first method is defined. Which means that none of > the properties or methods of the class could influence codegen. > > Frankly, I don't think that attributes on methods or properties are > realistic -- at least, not as part of the original class definition. > What I think you'd be looking at is the ability to define a class > wrapper that wraps the initially-defined dynamic class with a new > statically-defined class that allows you to put attributes on methods > and properties. Hmm... where have I heard that recently... :) > Getting attributes on classes would be a start - but for example with Silverlight you would want to be able to mark methods as 'Scriptable'. It sounds like Dino has some ideas on this though. When I was thinking about auto generating static assemblies from Python source it did occur to me that it would be possible to use simple markers to enable attributes... Michael > -- > Curt Hagenlocher > curt at hagenlocher.org > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From kfarmer at thuban.org Tue Feb 5 01:07:52 2008 From: kfarmer at thuban.org (Keith J. Farmer) Date: Mon, 4 Feb 2008 16:07:52 -0800 Subject: [IronPython] Decorators on classes References: <47A76D2D.2040500@voidspace.org.uk><7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com><47A78B78.4070903@voidspace.org.uk><7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com><47A797BD.7010906@voidspace.org.uk><47A79FE6.4050606@voidspace.org.uk> Message-ID: My personal experience says that the most prevalent use of attributes in .NET *is* on methods and properties, as part of the original class definition. Consider: LINQ to SQL: http://msdn2.microsoft.com/en-us/library/bb386971.aspx WCF: http://linqinaction.net/blogs/jwooley/archive/2007/05/14/wcf-with-the-linq-to-sql-designer.aspx XML Serialization: http://www.devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=236 ________________________________ From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher Sent: Mon 2/4/2008 3:46 PM To: Discussion of IronPython Subject: Re: [IronPython] Decorators on classes On Feb 4, 2008 3:29 PM, Michael Foord wrote: > > It is rather ugly. :-) Thanks; I thought so myself. > Would this technique have anything to offer for attributes on methods > and properties (etc). It's hard to see how, but it's been a while since I looked at that part of the source. I'm pretty sure that the CLR class itself needs to be emitted entirely by the contents of the one "class" statement -- and well before the first method is defined. Which means that none of the properties or methods of the class could influence codegen. Frankly, I don't think that attributes on methods or properties are realistic -- at least, not as part of the original class definition. What I think you'd be looking at is the ability to define a class wrapper that wraps the initially-defined dynamic class with a new statically-defined class that allows you to put attributes on methods and properties. Hmm... where have I heard that recently... :) -- Curt Hagenlocher curt at hagenlocher.org _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From fuzzyman at voidspace.org.uk Tue Feb 5 01:09:11 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Tue, 05 Feb 2008 00:09:11 +0000 Subject: [IronPython] Decorators on classes In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF47C8F53@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A78B78.4070903@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227011CF47C8F53@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <47A7A927.2080503@voidspace.org.uk> Dino Viehland wrote: > from future import clr_hacks sounds like the start of an awfully slippery slope. > lol :-) Although I do recall suggesting a while back that it might be impossible to avoid incompatible syntax if we are to have full LINQ support in IronPython, and that a future import would be one way to go... Michael > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher > Sent: Monday, February 04, 2008 2:54 PM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > On Feb 4, 2008 2:27 PM, Dino Viehland wrote: > >> As other people have pointed out decorators are a runtime concept and I >> don't think we get to change that. So consider a class decorator >> > > You could theoretically have a "slightly alternate" parsing mode that > recognizes a > specific class decorator name before the class definition is closed > (and therefore > before codegen). In other words, the following definition > > >> @ClrAttribute(System.SerializableAttribute) >> class X(ISomething, object): >> > > treats the decorator differently if it matches one of the special-case > names. The change in parsing could be triggered by something like > "from future import clr_hacks". > > > On Feb 4, 2008 2:32 PM, Keith J. Farmer wrote: > >> CPythonista outrage over not being able to read something they could >> never run is rather silly. :) >> > > You're clearly having trouble envisioning the following Slashdot > headline: "Microsoft inflicts 'embrace and extend' on Python". Silly > or not, perceptions are hugely important. > > -- > Curt Hagenlocher > curt at hagenlocher.org > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From kfarmer at thuban.org Tue Feb 5 01:18:53 2008 From: kfarmer at thuban.org (Keith J. Farmer) Date: Mon, 4 Feb 2008 16:18:53 -0800 Subject: [IronPython] Decorators on classes References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A78B78.4070903@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227011CF47C8F53@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A7A927.2080503@voidspace.org.uk> Message-ID: Py3k has ASTs, right? .. if the ASTs were mapped to System.Linq.Expressions wherever possible, that would be a great start. Even better if we got complaints if trying to cast an expression that couldn't be cast to the CLR nodes. ________________________________ From: users-bounces at lists.ironpython.com on behalf of Michael Foord Sent: Mon 2/4/2008 4:09 PM To: Discussion of IronPython Subject: Re: [IronPython] Decorators on classes Dino Viehland wrote: > from future import clr_hacks sounds like the start of an awfully slippery slope. > lol :-) Although I do recall suggesting a while back that it might be impossible to avoid incompatible syntax if we are to have full LINQ support in IronPython, and that a future import would be one way to go... Michael > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher > Sent: Monday, February 04, 2008 2:54 PM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > On Feb 4, 2008 2:27 PM, Dino Viehland wrote: > >> As other people have pointed out decorators are a runtime concept and I >> don't think we get to change that. So consider a class decorator >> > > You could theoretically have a "slightly alternate" parsing mode that > recognizes a > specific class decorator name before the class definition is closed > (and therefore > before codegen). In other words, the following definition > > >> @ClrAttribute(System.SerializableAttribute) >> class X(ISomething, object): >> > > treats the decorator differently if it matches one of the special-case > names. The change in parsing could be triggered by something like > "from future import clr_hacks". > > > On Feb 4, 2008 2:32 PM, Keith J. Farmer wrote: > >> CPythonista outrage over not being able to read something they could >> never run is rather silly. :) >> > > You're clearly having trouble envisioning the following Slashdot > headline: "Microsoft inflicts 'embrace and extend' on Python". Silly > or not, perceptions are hugely important. > > -- > Curt Hagenlocher > curt at hagenlocher.org > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From praveen at mahiti.org Tue Feb 5 06:38:45 2008 From: praveen at mahiti.org (Praveen Kumar) Date: Tue, 5 Feb 2008 11:08:45 +0530 Subject: [IronPython] Please help me out Message-ID: <6f7fd6e90802042138y9b09c9l962917ed77ea2bd7@mail.gmail.com> import SampleModule from SampleModule import SampleClass def Page_Load(): pass _PrivateMethod("1") PublicMethod("2") def _PrivateMethod(text): lblPrivate.Text="private %s" %text def PublicMethod(text): lblPublic.Text="public %s" %text def Private_Click(sender,args): _PrivateMethod("3") def Button1_Click(sender, args): sc = SampleClass() sc.TestString = TextBox1.Text Label1.Text = sc.TestString Label1.Visible="True" Then its showing error --------------->.. Value cannot be null. Parameter name: encoding. now i am happy atleast with the help of you i am able to resolve that error xlrd module is not found. please help me out to resolve this error. -- Praveen Kumar Mahiti Infotech Pvt. Ltd. # 33-34, Hennur Cross Hennur Main Road Bangalore, India - 560043 Mobile: +91 9343297314 Phone: +91 80 4148 5080/1 41150580/1 http://www.mahiti.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From n.s.buttar at gmail.com Tue Feb 5 07:10:19 2008 From: n.s.buttar at gmail.com (Navtej Singh) Date: Tue, 5 Feb 2008 11:40:19 +0530 Subject: [IronPython] Please help me out In-Reply-To: <6f7fd6e90802042138y9b09c9l962917ed77ea2bd7@mail.gmail.com> References: <6f7fd6e90802042138y9b09c9l962917ed77ea2bd7@mail.gmail.com> Message-ID: <1090e4100802042210i237143e9qf6efdd15c8b3f11e@mail.gmail.com> shouldnt it be Label1.Visible=True # (notice the missing quotes) On Feb 5, 2008 11:08 AM, Praveen Kumar wrote: > import SampleModule > from SampleModule import SampleClass > def Page_Load(): > pass > _PrivateMethod("1") > PublicMethod("2") > def _PrivateMethod(text): > lblPrivate.Text="private %s" %text > def PublicMethod(text): > lblPublic.Text="public %s" %text > def Private_Click(sender,args): > _PrivateMethod("3") > def Button1_Click(sender, args): > sc = SampleClass() > sc.TestString = TextBox1.Text > Label1.Text = sc.TestString > Label1.Visible="True" > Then its showing error --------------->.. Value cannot be null. > Parameter name: encoding. now i am happy atleast with the help of you i am > able to resolve that error xlrd module is not found. please help me out to > resolve this error. > > -- > Praveen Kumar > Mahiti Infotech Pvt. Ltd. > # 33-34, Hennur Cross > Hennur Main Road > Bangalore, India - 560043 > Mobile: +91 9343297314 > Phone: +91 80 4148 5080/1 41150580/1 > http://www.mahiti.org > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From fuzzyman at voidspace.org.uk Tue Feb 5 12:12:52 2008 From: fuzzyman at voidspace.org.uk (Fuzzyman) Date: Tue, 05 Feb 2008 11:12:52 +0000 Subject: [IronPython] Decorators on classes In-Reply-To: References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A78B78.4070903@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227011CF47C8F53@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A7A927.2080503@voidspace.org.uk> Message-ID: <47A844B4.7000308@voidspace.org.uk> Keith J. Farmer wrote: > Py3k has ASTs, right? > > .. if the ASTs were mapped to System.Linq.Expressions wherever possible, that would be a great start. Even better if we got complaints if trying to cast an expression that couldn't be cast to the CLR nodes. > Well - Python has had ASTs from the start through the compiler package: http://docs.python.org/lib/compiler.html The compiler contains libraries to generate an abstract syntax tree from Python source code and to generate Python bytecode from the tree. This is only available in FePy and not straight IronPython. Additionally, there's a super-secret "_ast" module in Python 2.5. Documented in the dev docs for 2.6 http://docs.python.org/dev/library/_ast.html The compiler package *is* being replaced in Python 3, but I don't know the details and a quick googling didn't reveal anything. Not sure how this helps with LINQ though as I don't believe that Python 3 ASTs will allow you to modify the grammar - so it could only help if you pass in your queries as strings? (Which is problematic as they need access to the enclosing namespace of course.) Michael http://www.manning.com/foord > ________________________________ > > From: users-bounces at lists.ironpython.com on behalf of Michael Foord > Sent: Mon 2/4/2008 4:09 PM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > > > Dino Viehland wrote: > >> from future import clr_hacks sounds like the start of an awfully slippery slope. >> >> > > lol :-) > > Although I do recall suggesting a while back that it might be impossible > to avoid incompatible syntax if we are to have full LINQ support in > IronPython, and that a future import would be one way to go... > > Michael > > >> -----Original Message----- >> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher >> Sent: Monday, February 04, 2008 2:54 PM >> To: Discussion of IronPython >> Subject: Re: [IronPython] Decorators on classes >> >> On Feb 4, 2008 2:27 PM, Dino Viehland wrote: >> >> >>> As other people have pointed out decorators are a runtime concept and I >>> don't think we get to change that. So consider a class decorator >>> >>> >> You could theoretically have a "slightly alternate" parsing mode that >> recognizes a >> specific class decorator name before the class definition is closed >> (and therefore >> before codegen). In other words, the following definition >> >> >> >>> @ClrAttribute(System.SerializableAttribute) >>> class X(ISomething, object): >>> >>> >> treats the decorator differently if it matches one of the special-case >> names. The change in parsing could be triggered by something like >> "from future import clr_hacks". >> >> >> On Feb 4, 2008 2:32 PM, Keith J. Farmer wrote: >> >> >>> CPythonista outrage over not being able to read something they could >>> never run is rather silly. :) >>> >>> >> You're clearly having trouble envisioning the following Slashdot >> headline: "Microsoft inflicts 'embrace and extend' on Python". Silly >> or not, perceptions are hugely important. >> >> -- >> Curt Hagenlocher >> curt at hagenlocher.org >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From hfoffani at gmail.com Tue Feb 5 12:49:17 2008 From: hfoffani at gmail.com (Hernan M Foffani) Date: Tue, 5 Feb 2008 12:49:17 +0100 Subject: [IronPython] Decorators on classes In-Reply-To: References: <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A78B78.4070903@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A797BD.7010906@voidspace.org.uk> <47A79FE6.4050606@voidspace.org.uk> Message-ID: <11fab4bc0802050349s1021e635jfeaf4e6fd9bc1ca6@mail.gmail.com> In our project 98% of attributes are on class definition and properties. The 2% left are field attributes, [field: NonSerialized()], on user defined events. On Feb 5, 2008 1:07 AM, Keith J. Farmer wrote: > My personal experience says that the most prevalent use of attributes in .NET *is* on methods > and properties, as part of the original class definition. > > Consider: > > LINQ to SQL: http://msdn2.microsoft.com/en-us/library/bb386971.aspx > > WCF: http://linqinaction.net/blogs/jwooley/archive/2007/05/14/wcf-with-the-linq-to-sql-designer.aspx > > XML Serialization: http://www.devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=236 > > > ________________________________ > > > It is rather ugly. :-) > > Thanks; I thought so myself. > > > Would this technique have anything to offer for attributes on methods > > and properties (etc). > > It's hard to see how, but it's been a while since I looked at that > part of the source. I'm pretty sure that the CLR class itself needs > to be emitted entirely by the contents of the one "class" statement -- > and well before the first method is defined. Which means that none of > the properties or methods of the class could influence codegen. > > Frankly, I don't think that attributes on methods or properties are > realistic -- at least, not as part of the original class definition. > What I think you'd be looking at is the ability to define a class > wrapper that wraps the initially-defined dynamic class with a new > statically-defined class that allows you to put attributes on methods > and properties. Hmm... where have I heard that recently... :) > From giles.thomas at resolversystems.com Tue Feb 5 14:50:45 2008 From: giles.thomas at resolversystems.com (Giles Thomas) Date: Tue, 05 Feb 2008 13:50:45 +0000 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: <47A79A3A.8070002@voidspace.org.uk> References: <47A75FA4.5090308@voidspace.org.uk> <47A76257.6090307@voidspace.org.uk> <47A79A3A.8070002@voidspace.org.uk> Message-ID: <47A869B5.8040505@resolversystems.com> Would it be hugely tricky to get it working in IP 1.1 as well as 2.0, do you think? I'm imagining some kind of "--target:1.1" flag to the tool. Michael Foord wrote: > Curt Hagenlocher wrote: > >> On Feb 4, 2008 11:07 AM, Michael Foord wrote: >> >> >>> Curt Hagenlocher wrote: >>> >>> >>>> The assemblies call into the IronPython engine (version 2) to load and >>>> execute the script. Currently, the script is loaded from the file >>>> system, but I'd eventually like to support embedding any >>>> required scripts as resources in the assembly, so that the whole thing >>>> can be distributed as a single neat package. >>>> >>>> >>> Great - you beat me to it. :-) >>> >>> If you make this open source then I'll be happy to help on it. >>> >>> >> I'm thinking of putting it on Codeplex. Be warned that I prefer ILGenerator to >> CodeDOM, probably because I'm reliving the glory years of assembly language >> programming. "6502 4eva!" :) >> >> > > Ouch. :-) > > Although in my case it was 68000 forever (truly beautiful CPU - based > appreciated inside an Amiga). I'd love to learn more about generating IL > - although it does make the learning curve steeper (I have tinkered but > nothing more). > > >> The current implementation is written in Python. >> >> > I would recommend leaving it in Python unless you have compelling > reasons to rewrite... > > I'm sure you will - but when you get it up on CodeDOM post an > announcement here so that I can blog about it. > > This is great news as it fills one 'missing piece of the puzzle' when it > comes to integrating IronPython with other .NET languages. > > Michael > > >> -- >> Curt Hagenlocher >> curt at hagenlocher.org >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > -- Giles Thomas MD & CTO, Resolver Systems Ltd. giles.thomas at resolversystems.com +44 (0) 20 7253 6372 Try out Resolver One! (Free registration required) 17a Clerkenwell Road, London EC1M 5RD, UK VAT No.: GB 893 5643 79 Registered in England and Wales as company number 5467329. Registered address: 843 Finchley Road, London NW11 8NA, UK -------------- next part -------------- An HTML attachment was scrubbed... URL: From rpigneri at LavaStorm.com Tue Feb 5 18:15:05 2008 From: rpigneri at LavaStorm.com (Pigneri, Rocco) Date: Tue, 5 Feb 2008 12:15:05 -0500 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: References: Message-ID: Curt, This is a great feature and was one of the first features that I investigated when I first got my hands on IP. I see an immediate need for this feature in using data binding with Windows Forms controls. Many controls (such as DataGridView and ListView) reflect over the properties of bound objects in order to display this data dynamically with no programmer setup. Because IP types are dynamic, WinForms cannot find any properties to bind and creates an "empty" object. In order to use these features now, I must create static interfaces with the required properties in a separate assembly and then inherit that interface whenever I bind to business objects. To make using these UI controls easier, it would be great if property statements could be turned into static properties either automatically or via a flag. It seems that IP already matches properties to the correct static getter/setter as defined in the interfaces so this should be a reasonable request. This staticization would remove the need for the separate static interface. Another situation in which this would be really helpful--although less critical--involves situations where I want to use a static tool on an IP assembly (for example, I want to use NUnit to test my IP classes). I say that this is not critical as a lot of tools already have Python-specific versions available--PyUnit is a good example. Finally, would there be a way to simplify programmer work by providing "standard" static creators that are turned on and off at a high level? For example, programmers could use a "compiler" switch to turn all functions into "void func(object, . . .)" and "object func(obj. . . )". I see this being useful in situations such as using NUnit because all that is really needed is the proper number of arguments and the right function name (all of which are already known in Python). If things then work the way that I think they work, you could then just pass the objects into the correct comparators, and if they are the right type, then the tests will run. Otherwise, you'll get an exception. Hope that helps, Rocco ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Monday, February 04, 2008 1:31 PM To: Discussion of IronPython Subject: [IronPython] Exporting Python code as an assembly After a bit of spare-time hacking this weekend, I've got a "proof-of-concept" program that takes a Python class and exports it as a (statically-defined) assembly. It uses Pythonic function annotations to signal attributes and input and output types to the wrapper generator. You end up with something like this def Test(object): @ClrAttribute(Xunit.FactAttribute) def WorthlessTest(self): Xunit.Assert.Equal[type(1)](1, 1) @ClrAccepts(System.String, System.Int32) @ClrReturns(System.Int32) def CalculateValue(self, s, i): return len(s) + i The program takes this source and spits out a DLL containing the class "Test" which implements "WorthlessTest" and "CalculateValue". The class itself contains a reference to the actual Python object, and each of the public functions simply delegates to the Pythonic implementation. I'm still working on cleaning up the source a little before releasing it, but was wondering if anyone had some feedback on the design as described so far. What should be changed or implemented in order for this to be more useful to you? Thanks, -Curt -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From curt at hagenlocher.org Tue Feb 5 18:22:40 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Tue, 5 Feb 2008 09:22:40 -0800 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: <47A869B5.8040505@resolversystems.com> References: <47A75FA4.5090308@voidspace.org.uk> <47A76257.6090307@voidspace.org.uk> <47A79A3A.8070002@voidspace.org.uk> <47A869B5.8040505@resolversystems.com> Message-ID: On Feb 5, 2008 5:50 AM, Giles Thomas wrote: > > Would it be hugely tricky to get it working in IP 1.1 as well as 2.0, do you think? > I'm imagining some kind of "--target:1.1" flag to the tool. I can't imagine that this would be a problem. It's been a while since I played with the hosting-level interfaces of 1.1, but I seem to recall that (at the level in question) they're largely isomorphic with what's currently in 2.0. -- Curt Hagenlocher curt at hagenlocher.org From curt at hagenlocher.org Tue Feb 5 18:26:22 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Tue, 5 Feb 2008 09:26:22 -0800 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: References: Message-ID: On Feb 5, 2008 9:15 AM, Pigneri, Rocco wrote: > > To make using these UI controls easier, it would be great if property > statements could be turned into static properties either automatically or > via a flag. Yes, one of the thoughts I had was that you should be able to run such a tool in a "greedy" mode (which tries to wrap everything) and a "precision" mode (which only wraps what you tell it to). -- Curt Hagenlocher curt at hagenlocher.org From giles.thomas at resolversystems.com Tue Feb 5 19:11:47 2008 From: giles.thomas at resolversystems.com (Giles Thomas) Date: Tue, 05 Feb 2008 18:11:47 +0000 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: References: <47A75FA4.5090308@voidspace.org.uk> <47A76257.6090307@voidspace.org.uk> <47A79A3A.8070002@voidspace.org.uk> <47A869B5.8040505@resolversystems.com> Message-ID: <47A8A6E3.1050200@resolversystems.com> Curt Hagenlocher wrote: > I can't imagine that this would be a problem. It's been a while since > I played with the hosting-level interfaces of 1.1, but I seem to > recall that (at the level in question) they're largely isomorphic with > what's currently in 2.0. Excellent - that's what I thought. I'd love to add that once it's online. Cheers, Giles -- Giles Thomas MD & CTO, Resolver Systems Ltd. giles.thomas at resolversystems.com +44 (0) 20 7253 6372 Try out Resolver One! (Free registration required) 17a Clerkenwell Road, London EC1M 5RD, UK VAT No.: GB 893 5643 79 Registered in England and Wales as company number 5467329. Registered address: 843 Finchley Road, London NW11 8NA, UK From kfarmer at thuban.org Tue Feb 5 19:55:58 2008 From: kfarmer at thuban.org (Keith J. Farmer) Date: Tue, 5 Feb 2008 10:55:58 -0800 Subject: [IronPython] Decorators on classes References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A78B78.4070903@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227011CF47C8F53@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A7A927.2080503@voidspace.org.uk> <47A844B4.7000308@voidspace.org.uk> Message-ID: "I am only an egg." The basic requirement for IQueryable (and, by extension as it were, the interesting variations of LINQ providers) is that the compiler be able to emit a series of calls to build expressions. I only imagine (read: I haven't studied Python's AST offerings) that *for the most part* it should be a fairly straightforward mapping of a subset to the new Expressions namespace. Enough that probably a fairly simple visitor could transform from one to the other. Using dotted notation for the query operators themselves is okay. Creating new Expression trees is a PITA without help. ________________________________ From: users-bounces at lists.ironpython.com on behalf of Fuzzyman Sent: Tue 2/5/2008 3:12 AM To: Discussion of IronPython Subject: Re: [IronPython] Decorators on classes Keith J. Farmer wrote: > Py3k has ASTs, right? > > .. if the ASTs were mapped to System.Linq.Expressions wherever possible, that would be a great start. Even better if we got complaints if trying to cast an expression that couldn't be cast to the CLR nodes. > Well - Python has had ASTs from the start through the compiler package: http://docs.python.org/lib/compiler.html The compiler contains libraries to generate an abstract syntax tree from Python source code and to generate Python bytecode from the tree. This is only available in FePy and not straight IronPython. Additionally, there's a super-secret "_ast" module in Python 2.5. Documented in the dev docs for 2.6 http://docs.python.org/dev/library/_ast.html The compiler package *is* being replaced in Python 3, but I don't know the details and a quick googling didn't reveal anything. Not sure how this helps with LINQ though as I don't believe that Python 3 ASTs will allow you to modify the grammar - so it could only help if you pass in your queries as strings? (Which is problematic as they need access to the enclosing namespace of course.) Michael http://www.manning.com/foord > ________________________________ > > From: users-bounces at lists.ironpython.com on behalf of Michael Foord > Sent: Mon 2/4/2008 4:09 PM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > > > Dino Viehland wrote: > >> from future import clr_hacks sounds like the start of an awfully slippery slope. >> >> > > lol :-) > > Although I do recall suggesting a while back that it might be impossible > to avoid incompatible syntax if we are to have full LINQ support in > IronPython, and that a future import would be one way to go... > > Michael > > >> -----Original Message----- >> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher >> Sent: Monday, February 04, 2008 2:54 PM >> To: Discussion of IronPython >> Subject: Re: [IronPython] Decorators on classes >> >> On Feb 4, 2008 2:27 PM, Dino Viehland wrote: >> >> >>> As other people have pointed out decorators are a runtime concept and I >>> don't think we get to change that. So consider a class decorator >>> >>> >> You could theoretically have a "slightly alternate" parsing mode that >> recognizes a >> specific class decorator name before the class definition is closed >> (and therefore >> before codegen). In other words, the following definition >> >> >> >>> @ClrAttribute(System.SerializableAttribute) >>> class X(ISomething, object): >>> >>> >> treats the decorator differently if it matches one of the special-case >> names. The change in parsing could be triggered by something like >> "from future import clr_hacks". >> >> >> On Feb 4, 2008 2:32 PM, Keith J. Farmer wrote: >> >> >>> CPythonista outrage over not being able to read something they could >>> never run is rather silly. :) >>> >>> >> You're clearly having trouble envisioning the following Slashdot >> headline: "Microsoft inflicts 'embrace and extend' on Python". Silly >> or not, perceptions are hugely important. >> >> -- >> Curt Hagenlocher >> curt at hagenlocher.org >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From curt at hagenlocher.org Tue Feb 5 21:00:08 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Tue, 5 Feb 2008 12:00:08 -0800 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: <47A8A6E3.1050200@resolversystems.com> References: <47A75FA4.5090308@voidspace.org.uk> <47A76257.6090307@voidspace.org.uk> <47A79A3A.8070002@voidspace.org.uk> <47A869B5.8040505@resolversystems.com> <47A8A6E3.1050200@resolversystems.com> Message-ID: You can download my work-in-progress from http://hagenlocher.org/software/ClrWrapper.zip The source consists of the three files ClrBuilder.py, ClrWrapper.py and MakeModule.py. There are also two "demo" files: Xtest.py and WcfServer.py. The program can currently be run as follows: PS F:\IronPython-2.0A8> *.\ipy.exe MakeModule.py Xtest.py* This will produce a file called Xtest.dll. At this point, the application doesn't require any of the standard Python library files. It's only been tried with the Alpha 8 binaries -- and in fact, the hosting interfaces for IronPython still aren't entirely stable so there's no guarantee that the DLLs produced will work with Alpha 9. Xtest.py is a trivial application that implements a single xunit-compatible unit test PS F:\IronPython-2.0A8> *.\xunit.console.exe Xtest.dll /noshadow* . Total tests: 1, Failures: 0, Skipped: 0, Time: 0.275 seconds WcfServer.py theoretically implements a WCF server, though I haven't gotten as far as actually testing the output yet. (The generated code passes the eyeball compiler.) Code quality is unimpressive; your mileage may vary. And I've got to get back to my "day job" for a few hours now :). -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From riltim at gmail.com Tue Feb 5 22:24:38 2008 From: riltim at gmail.com (Tim Riley) Date: Tue, 5 Feb 2008 16:24:38 -0500 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: References: <47A75FA4.5090308@voidspace.org.uk> <47A76257.6090307@voidspace.org.uk> <47A79A3A.8070002@voidspace.org.uk> <47A869B5.8040505@resolversystems.com> <47A8A6E3.1050200@resolversystems.com> Message-ID: I was testing out the code provided and when I tested it using the example I got the following error. Note: I'm using IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.1433 C:\Documents and Settings\TJRiley\Desktop\ClrWrapper>ipy.exe MakeModule.py Xtest.py Traceback (most recent call last): File , line unknown, in _stub_##2 File C:\Documents and Settings\TJRiley\Desktop\ClrWrapper\Xtest.py, line 4, in Initialize File MakeModule.py, line 331, in Initialize File MakeModule.py, line 39, in GetExportedClasses IOError: Could not add reference to assembly xunit.dll On Feb 5, 2008 3:00 PM, Curt Hagenlocher wrote: > You can download my work-in-progress from > http://hagenlocher.org/software/ClrWrapper.zip > > The source consists of the three files ClrBuilder.py, ClrWrapper.py and > MakeModule.py. There are also two "demo" files: Xtest.py and WcfServer.py. > The program can currently be run as follows: > > PS F:\IronPython-2.0A8> .\ipy.exe MakeModule.py Xtest.py > > This will produce a file called Xtest.dll. > > At this point, the application doesn't require any of the standard Python > library files. It's only been tried with the Alpha 8 binaries -- and in > fact, the hosting interfaces for IronPython still aren't entirely stable so > there's no guarantee that the DLLs produced will work with Alpha 9. > > Xtest.py is a trivial application that implements a single xunit-compatible > unit test > PS F:\IronPython-2.0A8> .\xunit.console.exe Xtest.dll /noshadow > . > Total tests: 1, Failures: 0, Skipped: 0, Time: 0.275 seconds > > WcfServer.py theoretically implements a WCF server, though I haven't gotten > as far as actually testing the output yet. (The generated code passes the > eyeball compiler.) > > Code quality is unimpressive; your mileage may vary. And I've got to get > back to my "day job" for a few hours now :). > > > > -- > Curt Hagenlocher > curt at hagenlocher.org > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From curt at hagenlocher.org Tue Feb 5 22:29:04 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Tue, 5 Feb 2008 13:29:04 -0800 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: References: <47A76257.6090307@voidspace.org.uk> <47A79A3A.8070002@voidspace.org.uk> <47A869B5.8040505@resolversystems.com> <47A8A6E3.1050200@resolversystems.com> Message-ID: On Feb 5, 2008 1:24 PM, Tim Riley wrote: > I was testing out the code provided and when I tested it using the > example I got the following error. > > [snip] > IOError: Could not add reference to assembly xunit.dll Sorry, you need xunit for that -- it's not part of IronPython. Xunit is a kind of "next generation NUnit" for unit testing, and I recommend it highly. You can find it at http://www.codeplex.com/xunit -- Curt Hagenlocher curt at hagenlocher.org From dinov at exchange.microsoft.com Tue Feb 5 22:54:42 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Tue, 5 Feb 2008 13:54:42 -0800 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: References: Message-ID: <7AD436E4270DD54A94238001769C2227011CF47C9182@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Data binding isn't working for you? We have support for this via CustomTypeDescriptors which describe the Python objects and we have some test cases to verify it works. Note it was broken before 1.1.1 although it's been working in 2.0 for a little while now. For example: import clr clr.AddReference('System.Windows.Forms') import System.Windows.Forms as SWF import System class AgeQualifier(object): def __get__(self, instance, ctx): if instance.Age < 13: return 'young' if instance.Age < 20: return 'teen' if instance.Age < 30: return 'twenties' if instance.Age < 40: return 'thirties' if instance.Age < 50: return 'forties' return 'old' SAMPLE_DATA = [('Joe', 23, 'twenties'), ('Bob', 8, 'young'), ('Thomas', 32, 'thirties'), ('Patrick', 41, 'forties'), ('Kathy', 19, 'teen'), ('Sue' , 77, 'old'),] class Person(System.Object): def __init__(self, name, age): self._name = name self._age = age def get_name(self): return self._name def set_name(self, value): self._name = value Name = property(get_name, set_name) def get_age(self): return self._age def set_age(self, value): self._age = value Age = property(get_age, set_age) AgeDescription = AgeQualifier() class Form(SWF.Form): def __init__(self): SWF.Form.__init__(self) self._people = people = [] for name, age, ignored in SAMPLE_DATA: people.append(Person(name, age)) grid = SWF.DataGridView() grid.AutoGenerateColumns = True grid.DataSource = people grid.Dock = SWF.DockStyle.Fill self.grid = grid self.Controls.Add(grid) form = Form() SWF.Application.Run(form) From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Pigneri, Rocco Sent: Tuesday, February 05, 2008 9:15 AM To: Discussion of IronPython Subject: Re: [IronPython] Exporting Python code as an assembly Curt, This is a great feature and was one of the first features that I investigated when I first got my hands on IP. I see an immediate need for this feature in using data binding with Windows Forms controls. Many controls (such as DataGridView and ListView) reflect over the properties of bound objects in order to display this data dynamically with no programmer setup. Because IP types are dynamic, WinForms cannot find any properties to bind and creates an "empty" object. In order to use these features now, I must create static interfaces with the required properties in a separate assembly and then inherit that interface whenever I bind to business objects. To make using these UI controls easier, it would be great if property statements could be turned into static properties either automatically or via a flag. It seems that IP already matches properties to the correct static getter/setter as defined in the interfaces so this should be a reasonable request. This staticization would remove the need for the separate static interface. Another situation in which this would be really helpful--although less critical--involves situations where I want to use a static tool on an IP assembly (for example, I want to use NUnit to test my IP classes). I say that this is not critical as a lot of tools already have Python-specific versions available--PyUnit is a good example. Finally, would there be a way to simplify programmer work by providing "standard" static creators that are turned on and off at a high level? For example, programmers could use a "compiler" switch to turn all functions into "void func(object, . . .)" and "object func(obj. . . )". I see this being useful in situations such as using NUnit because all that is really needed is the proper number of arguments and the right function name (all of which are already known in Python). If things then work the way that I think they work, you could then just pass the objects into the correct comparators, and if they are the right type, then the tests will run. Otherwise, you'll get an exception. Hope that helps, Rocco ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Monday, February 04, 2008 1:31 PM To: Discussion of IronPython Subject: [IronPython] Exporting Python code as an assembly After a bit of spare-time hacking this weekend, I've got a "proof-of-concept" program that takes a Python class and exports it as a (statically-defined) assembly. It uses Pythonic function annotations to signal attributes and input and output types to the wrapper generator. You end up with something like this def Test(object): @ClrAttribute(Xunit.FactAttribute) def WorthlessTest(self): Xunit.Assert.Equal[type(1)](1, 1) @ClrAccepts(System.String, System.Int32) @ClrReturns(System.Int32) def CalculateValue(self, s, i): return len(s) + i The program takes this source and spits out a DLL containing the class "Test" which implements "WorthlessTest" and "CalculateValue". The class itself contains a reference to the actual Python object, and each of the public functions simply delegates to the Pythonic implementation. I'm still working on cleaning up the source a little before releasing it, but was wondering if anyone had some feedback on the design as described so far. What should be changed or implemented in order for this to be more useful to you? Thanks, -Curt -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From curt at hagenlocher.org Tue Feb 5 23:40:26 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Tue, 5 Feb 2008 14:40:26 -0800 Subject: [IronPython] Easy Access to the DLR from C# Message-ID: For the five people here who aren't on it, the following link was posted to the IronRuby mailing list: http://blogs.msdn.com/charlie/archive/2008/01/25/future-focus.aspx -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From riltim at gmail.com Wed Feb 6 00:10:14 2008 From: riltim at gmail.com (Tim Riley) Date: Tue, 5 Feb 2008 18:10:14 -0500 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: References: <47A76257.6090307@voidspace.org.uk> <47A79A3A.8070002@voidspace.org.uk> <47A869B5.8040505@resolversystems.com> <47A8A6E3.1050200@resolversystems.com> Message-ID: Well don't I feel like a moron. I should have spotted that. I apologize for posting before thinking. On Feb 5, 2008 4:29 PM, Curt Hagenlocher wrote: > On Feb 5, 2008 1:24 PM, Tim Riley wrote: > > I was testing out the code provided and when I tested it using the > > example I got the following error. > > > > [snip] > > IOError: Could not add reference to assembly xunit.dll > > Sorry, you need xunit for that -- it's not part of IronPython. Xunit > is a kind of "next generation NUnit" for unit testing, and I recommend > it highly. You can find it at http://www.codeplex.com/xunit > > > > -- > Curt Hagenlocher > curt at hagenlocher.org > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From fuzzyman at voidspace.org.uk Wed Feb 6 00:57:43 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Tue, 05 Feb 2008 23:57:43 +0000 Subject: [IronPython] Easy Access to the DLR from C# In-Reply-To: References: Message-ID: <47A8F7F7.7060701@voidspace.org.uk> Curt Hagenlocher wrote: > For the five people here who aren't on it, the following link was > posted to the IronRuby mailing list: > http://blogs.msdn.com/charlie/archive/2008/01/25/future-focus.aspx Plus the two who don't subscribe to IronPython-URLs ;-) http://ironpython-urls.blogspot.com/2008/01/dynamic-lookup-in-c.html Michael > > -- > Curt Hagenlocher > curt at hagenlocher.org > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From praveen at mahiti.org Wed Feb 6 11:44:33 2008 From: praveen at mahiti.org (Praveen Kumar) Date: Wed, 6 Feb 2008 16:14:33 +0530 Subject: [IronPython] Value can not be null Message-ID: <6f7fd6e90802060244n373b9a78s23cc1d70f0150baf@mail.gmail.com> Hi I am new of ironPython for VisualStudio.net 2005 Description of SampleModule1---> import sys print>>sys.stderr, "SampleModule: being imported" Description of SampleModule2--> # coding: cp1252 print "Hi" Default.aspx.py------> import System from System.Data import * from System.Web import * from System.Web.UI import * from clr import * import sys import SampleModule2 print >> sys.stderr, "aspx: module imported OK" Error-->value canot be null and getting troubleshooting tips 1-use the "new" keyword to create object instance 2-check to determine if the object is null before claaing the method Now second issue when i import SampleModule1 Its working failrly but nothing is printing on page. -- Praveen Kumar Mahiti Infotech Pvt. Ltd. # 33-34, Hennur Cross Hennur Main Road Bangalore, India - 560043 Mobile: +91 9343297314 Phone: +91 80 4148 5080/1 41150580/1 http://www.mahiti.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Wed Feb 6 18:02:54 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 6 Feb 2008 09:02:54 -0800 Subject: [IronPython] Value can not be null In-Reply-To: <6f7fd6e90802060244n373b9a78s23cc1d70f0150baf@mail.gmail.com> References: <6f7fd6e90802060244n373b9a78s23cc1d70f0150baf@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF47C931A@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Is this using ASP.NET futures? From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Praveen Kumar Sent: Wednesday, February 06, 2008 2:45 AM To: users at lists.ironpython.com Subject: [IronPython] Value can not be null Hi I am new of ironPython for VisualStudio.net 2005 Description of SampleModule1---> import sys print>>sys.stderr, "SampleModule: being imported" Description of SampleModule2--> # coding: cp1252 print "Hi" Default.aspx.py------> import System from System.Data import * from System.Web import * from System.Web.UI import * from clr import * import sys import SampleModule2 print >> sys.stderr, "aspx: module imported OK" Error-->value canot be null and getting troubleshooting tips 1-use the "new" keyword to create object instance 2-check to determine if the object is null before claaing the method Now second issue when i import SampleModule1 Its working failrly but nothing is printing on page. -- Praveen Kumar Mahiti Infotech Pvt. Ltd. # 33-34, Hennur Cross Hennur Main Road Bangalore, India - 560043 Mobile: +91 9343297314 Phone: +91 80 4148 5080/1 41150580/1 http://www.mahiti.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From SomethingNew2_0 at hotmail.com Wed Feb 6 18:55:52 2008 From: SomethingNew2_0 at hotmail.com (Herny Johnson) Date: Wed, 6 Feb 2008 11:55:52 -0600 Subject: [IronPython] Delegates Message-ID: I'm trying to put Xna on a Windows Form and the best idea that I've found so far was at http://creators.xna.com/Headlines/developmentaspx/archive/2007/01/01/WinForms-Series-1_3A00_--Graphics-Device.aspx. In a nut shell it's quite easy to translate the C# code to IronPython to see if it will actually work for IronPython. That is until the C# code: C# // Hook the idle event to constantly redraw our animation. Application.Idle += delegate { Invalidate(); }; This makes it so the Xna control that you create it constantly redrawn, not just every button click or other event. This code is found in the SpinningTriangleControl.cs of the zipfile if you want to see more of how it works. My question is how do I create a delegate or equivalent in IronPython? I've tried using System.Delegate, but I'm not sure how to use it correctly. Also I've tried just usingApplication.Idle += self.Invalidate (called or uncalled) and that doesn't work. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Wed Feb 6 19:09:08 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 6 Feb 2008 10:09:08 -0800 Subject: [IronPython] Delegates In-Reply-To: References: Message-ID: <7AD436E4270DD54A94238001769C2227011CF47C9353@DF-GRTDANE-MSG.exchange.corp.microsoft.com> You need to match the signature of Application.Idle. But once you have the right signature += should work. It looks like Idle is just an EventHandler so: def MyIdle(self, sender, eventArgs): self.Invalidate() Application.Idle += self.MyIdle Should work. And to make it more like the C# version you can use a lambda: Application.Idle += lambda sender, ea: self.Invalidate() From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Herny Johnson Sent: Wednesday, February 06, 2008 9:56 AM To: users at lists.ironpython.com Subject: [IronPython] Delegates I'm trying to put Xna on a Windows Form and the best idea that I've found so far was at http://creators.xna.com/Headlines/developmentaspx/archive/2007/01/01/WinForms-Series-1_3A00_--Graphics-Device.aspx. In a nut shell it's quite easy to translate the C# code to IronPython to see if it will actually work for IronPython. That is until the C# code: C# // Hook the idle event to constantly redraw our animation. Application.Idle += delegate { Invalidate(); }; This makes it so the Xna control that you create it constantly redrawn, not just every button click or other event. This code is found in the SpinningTriangleControl.cs of the zip file if you want to see more of how it works. My question is how do I create a delegate or equivalent in IronPython? I've tried using System.Delegate, but I'm not sure how to use it correctly. Also I've tried just using Application.Idle += self.Invalidate (called or uncalled) and that doesn't work. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rpigneri at LavaStorm.com Wed Feb 6 21:46:46 2008 From: rpigneri at LavaStorm.com (Pigneri, Rocco) Date: Wed, 6 Feb 2008 15:46:46 -0500 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF47C9182@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <7AD436E4270DD54A94238001769C2227011CF47C9182@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: Dino, Ah ha! Well, it didn't work under 1.1, but under 1.1.1, it worked nearly right out of the box. When I used a static interface under 1.1, I only got the static properties in the DataGridView. However, under 1.1.1, I am getting a whole extra slew of information in my Grids (__weakref__, __doc__, the hidden values, the properties themselves, every function in the type) when I turn on AutoColumnGenerate. Is this what I should be expecting? Also, it seems that if I turn on user creation of new elements (BindingList.AllowNew = True), then the component crashes with an error stating that it cannot find the constructor for my type, whether or not I have defined it. Is this also to be expected or not? Thank you, Rocco Pigneri ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dino Viehland Sent: Tuesday, February 05, 2008 4:55 PM To: Discussion of IronPython Subject: Re: [IronPython] Exporting Python code as an assembly Data binding isn't working for you? We have support for this via CustomTypeDescriptors which describe the Python objects and we have some test cases to verify it works. Note it was broken before 1.1.1 although it's been working in 2.0 for a little while now. For example: import clr clr.AddReference('System.Windows.Forms') import System.Windows.Forms as SWF import System class AgeQualifier(object): def __get__(self, instance, ctx): if instance.Age < 13: return 'young' if instance.Age < 20: return 'teen' if instance.Age < 30: return 'twenties' if instance.Age < 40: return 'thirties' if instance.Age < 50: return 'forties' return 'old' SAMPLE_DATA = [('Joe', 23, 'twenties'), ('Bob', 8, 'young'), ('Thomas', 32, 'thirties'), ('Patrick', 41, 'forties'), ('Kathy', 19, 'teen'), ('Sue' , 77, 'old'),] class Person(System.Object): def __init__(self, name, age): self._name = name self._age = age def get_name(self): return self._name def set_name(self, value): self._name = value Name = property(get_name, set_name) def get_age(self): return self._age def set_age(self, value): self._age = value Age = property(get_age, set_age) AgeDescription = AgeQualifier() class Form(SWF.Form): def __init__(self): SWF.Form.__init__(self) self._people = people = [] for name, age, ignored in SAMPLE_DATA: people.append(Person(name, age)) grid = SWF.DataGridView() grid.AutoGenerateColumns = True grid.DataSource = people grid.Dock = SWF.DockStyle.Fill self.grid = grid self.Controls.Add(grid) form = Form() SWF.Application.Run(form) From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Pigneri, Rocco Sent: Tuesday, February 05, 2008 9:15 AM To: Discussion of IronPython Subject: Re: [IronPython] Exporting Python code as an assembly Curt, This is a great feature and was one of the first features that I investigated when I first got my hands on IP. I see an immediate need for this feature in using data binding with Windows Forms controls. Many controls (such as DataGridView and ListView) reflect over the properties of bound objects in order to display this data dynamically with no programmer setup. Because IP types are dynamic, WinForms cannot find any properties to bind and creates an "empty" object. In order to use these features now, I must create static interfaces with the required properties in a separate assembly and then inherit that interface whenever I bind to business objects. To make using these UI controls easier, it would be great if property statements could be turned into static properties either automatically or via a flag. It seems that IP already matches properties to the correct static getter/setter as defined in the interfaces so this should be a reasonable request. This staticization would remove the need for the separate static interface. Another situation in which this would be really helpful--although less critical--involves situations where I want to use a static tool on an IP assembly (for example, I want to use NUnit to test my IP classes). I say that this is not critical as a lot of tools already have Python-specific versions available--PyUnit is a good example. Finally, would there be a way to simplify programmer work by providing "standard" static creators that are turned on and off at a high level? For example, programmers could use a "compiler" switch to turn all functions into "void func(object, . . .)" and "object func(obj. . . )". I see this being useful in situations such as using NUnit because all that is really needed is the proper number of arguments and the right function name (all of which are already known in Python). If things then work the way that I think they work, you could then just pass the objects into the correct comparators, and if they are the right type, then the tests will run. Otherwise, you'll get an exception. Hope that helps, Rocco ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Monday, February 04, 2008 1:31 PM To: Discussion of IronPython Subject: [IronPython] Exporting Python code as an assembly After a bit of spare-time hacking this weekend, I've got a "proof-of-concept" program that takes a Python class and exports it as a (statically-defined) assembly. It uses Pythonic function annotations to signal attributes and input and output types to the wrapper generator. You end up with something like this def Test(object): @ClrAttribute(Xunit.FactAttribute) def WorthlessTest(self): Xunit.Assert.Equal[type(1)](1, 1) @ClrAccepts(System.String, System.Int32) @ClrReturns(System.Int32) def CalculateValue(self, s, i): return len(s) + i The program takes this source and spits out a DLL containing the class "Test" which implements "WorthlessTest" and "CalculateValue". The class itself contains a reference to the actual Python object, and each of the public functions simply delegates to the Pythonic implementation. I'm still working on cleaning up the source a little before releasing it, but was wondering if anyone had some feedback on the design as described so far. What should be changed or implemented in order for this to be more useful to you? Thanks, -Curt -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Wed Feb 6 21:54:08 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 6 Feb 2008 12:54:08 -0800 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: References: <7AD436E4270DD54A94238001769C2227011CF47C9182@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF47C9430@DF-GRTDANE-MSG.exchange.corp.microsoft.com> The extra __'s are expected. When we enabled this in 1.1.1 we didn't want to significantly alter the experience between 1.1 and 1.1.1. The problem with 1.1 was that if the caller passed in an attribute to filter by (DataGridView passes in BrowsableAttribute) we would say "attributes? We don't have attributes, so you'll get an empty collection". In 1.1.1 we'll return just about anything if browsable is set. In 2.0, where we have a little more leeway to change things, we're more aggressive about filtering out things you probably don't want to see. You can always not auto-generate the columns and you'll get the columns you presumably want. The AllowNew is going to be an unfortunate limitation - Python type instances can't (easily) be created by anyone except for the Python runtime. The reason is we need to pass a PythonType object into the contructor so the object knows it's type in the Python world. So we probably can't do much about this one :(. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Pigneri, Rocco Sent: Wednesday, February 06, 2008 12:47 PM To: Discussion of IronPython Subject: Re: [IronPython] Exporting Python code as an assembly Dino, Ah ha! Well, it didn't work under 1.1, but under 1.1.1, it worked nearly right out of the box. When I used a static interface under 1.1, I only got the static properties in the DataGridView. However, under 1.1.1, I am getting a whole extra slew of information in my Grids (__weakref__, __doc__, the hidden values, the properties themselves, every function in the type) when I turn on AutoColumnGenerate. Is this what I should be expecting? Also, it seems that if I turn on user creation of new elements (BindingList.AllowNew = True), then the component crashes with an error stating that it cannot find the constructor for my type, whether or not I have defined it. Is this also to be expected or not? Thank you, Rocco Pigneri ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dino Viehland Sent: Tuesday, February 05, 2008 4:55 PM To: Discussion of IronPython Subject: Re: [IronPython] Exporting Python code as an assembly Data binding isn't working for you? We have support for this via CustomTypeDescriptors which describe the Python objects and we have some test cases to verify it works. Note it was broken before 1.1.1 although it's been working in 2.0 for a little while now. For example: import clr clr.AddReference('System.Windows.Forms') import System.Windows.Forms as SWF import System class AgeQualifier(object): def __get__(self, instance, ctx): if instance.Age < 13: return 'young' if instance.Age < 20: return 'teen' if instance.Age < 30: return 'twenties' if instance.Age < 40: return 'thirties' if instance.Age < 50: return 'forties' return 'old' SAMPLE_DATA = [('Joe', 23, 'twenties'), ('Bob', 8, 'young'), ('Thomas', 32, 'thirties'), ('Patrick', 41, 'forties'), ('Kathy', 19, 'teen'), ('Sue' , 77, 'old'),] class Person(System.Object): def __init__(self, name, age): self._name = name self._age = age def get_name(self): return self._name def set_name(self, value): self._name = value Name = property(get_name, set_name) def get_age(self): return self._age def set_age(self, value): self._age = value Age = property(get_age, set_age) AgeDescription = AgeQualifier() class Form(SWF.Form): def __init__(self): SWF.Form.__init__(self) self._people = people = [] for name, age, ignored in SAMPLE_DATA: people.append(Person(name, age)) grid = SWF.DataGridView() grid.AutoGenerateColumns = True grid.DataSource = people grid.Dock = SWF.DockStyle.Fill self.grid = grid self.Controls.Add(grid) form = Form() SWF.Application.Run(form) From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Pigneri, Rocco Sent: Tuesday, February 05, 2008 9:15 AM To: Discussion of IronPython Subject: Re: [IronPython] Exporting Python code as an assembly Curt, This is a great feature and was one of the first features that I investigated when I first got my hands on IP. I see an immediate need for this feature in using data binding with Windows Forms controls. Many controls (such as DataGridView and ListView) reflect over the properties of bound objects in order to display this data dynamically with no programmer setup. Because IP types are dynamic, WinForms cannot find any properties to bind and creates an "empty" object. In order to use these features now, I must create static interfaces with the required properties in a separate assembly and then inherit that interface whenever I bind to business objects. To make using these UI controls easier, it would be great if property statements could be turned into static properties either automatically or via a flag. It seems that IP already matches properties to the correct static getter/setter as defined in the interfaces so this should be a reasonable request. This staticization would remove the need for the separate static interface. Another situation in which this would be really helpful--although less critical--involves situations where I want to use a static tool on an IP assembly (for example, I want to use NUnit to test my IP classes). I say that this is not critical as a lot of tools already have Python-specific versions available--PyUnit is a good example. Finally, would there be a way to simplify programmer work by providing "standard" static creators that are turned on and off at a high level? For example, programmers could use a "compiler" switch to turn all functions into "void func(object, . . .)" and "object func(obj. . . )". I see this being useful in situations such as using NUnit because all that is really needed is the proper number of arguments and the right function name (all of which are already known in Python). If things then work the way that I think they work, you could then just pass the objects into the correct comparators, and if they are the right type, then the tests will run. Otherwise, you'll get an exception. Hope that helps, Rocco ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Monday, February 04, 2008 1:31 PM To: Discussion of IronPython Subject: [IronPython] Exporting Python code as an assembly After a bit of spare-time hacking this weekend, I've got a "proof-of-concept" program that takes a Python class and exports it as a (statically-defined) assembly. It uses Pythonic function annotations to signal attributes and input and output types to the wrapper generator. You end up with something like this def Test(object): @ClrAttribute(Xunit.FactAttribute) def WorthlessTest(self): Xunit.Assert.Equal[type(1)](1, 1) @ClrAccepts(System.String, System.Int32) @ClrReturns(System.Int32) def CalculateValue(self, s, i): return len(s) + i The program takes this source and spits out a DLL containing the class "Test" which implements "WorthlessTest" and "CalculateValue". The class itself contains a reference to the actual Python object, and each of the public functions simply delegates to the Pythonic implementation. I'm still working on cleaning up the source a little before releasing it, but was wondering if anyone had some feedback on the design as described so far. What should be changed or implemented in order for this to be more useful to you? Thanks, -Curt -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From curt at hagenlocher.org Thu Feb 7 00:25:05 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Wed, 6 Feb 2008 15:25:05 -0800 Subject: [IronPython] staticmethod / classmethod and setattr Message-ID: This is really more of a Python question than an IronPython question, but I'm not currently on any non-Iron Python lists. :) The following definition results in an error under both CPython 2.5 and IronPython. Decorating a method as static or class prevents attributes being set on the resulting definition. def decorate(obj): obj.decorated = True return obj class X: @decorate @staticmethod def foo(): pass Does anyone know the "why" of this behavior? I can work around this problem by declaring the decorators in the opposite order, but it seems like an odd imposition to put on the consumers of the code in question. I'm worried that I'm missing something about the expected semantics of these standard functions. -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at voidspace.org.uk Thu Feb 7 00:44:37 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Wed, 06 Feb 2008 23:44:37 +0000 Subject: [IronPython] staticmethod / classmethod and setattr In-Reply-To: References: Message-ID: <47AA4665.3010007@voidspace.org.uk> Not really an answer but possibly an explanation. staticmethod and classmethod are descriptors that wrap callable objects. Because they are implemented in C they us __slots__ and you can't set arbitrary attributes on them. Michael Curt Hagenlocher wrote: > This is really more of a Python question than an IronPython question, > but I'm not currently on any non-Iron Python lists. :) > > The following definition results in an error under both CPython 2.5 > and IronPython. Decorating a method as static or class prevents > attributes being set on the resulting definition. > > def decorate(obj): > obj.decorated = True > return obj > > class X: > @decorate > @staticmethod > def foo(): > pass > > Does anyone know the "why" of this behavior? > > I can work around this problem by declaring the decorators in the > opposite order, but it seems like an odd imposition to put on the > consumers of the code in question. I'm worried that I'm missing > something about the expected semantics of these standard functions. > > -- > Curt Hagenlocher > curt at hagenlocher.org > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From fuzzyman at voidspace.org.uk Thu Feb 7 00:46:33 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Wed, 06 Feb 2008 23:46:33 +0000 Subject: [IronPython] staticmethod / classmethod and setattr In-Reply-To: References: Message-ID: <47AA46D9.8080109@voidspace.org.uk> From http://www.ddj.com/web-development/184406073 Usually, most decorators expect a function on input, and return either a function or an attribute descriptor as their output. The Python built-ins classmethod, staticmethod, and property all return attribute descriptors, so their output cannot be passed to a decorator that expects a function. That's why I had to put classmethod first in Listing Four. As an experiment, try reversing the order of @traced and @classmethod in Listing Four, and see if you can guess what will happen. Curt Hagenlocher wrote: > This is really more of a Python question than an IronPython question, > but I'm not currently on any non-Iron Python lists. :) > > The following definition results in an error under both CPython 2.5 > and IronPython. Decorating a method as static or class prevents > attributes being set on the resulting definition. > > def decorate(obj): > obj.decorated = True > return obj > > class X: > @decorate > @staticmethod > def foo(): > pass > > Does anyone know the "why" of this behavior? > > I can work around this problem by declaring the decorators in the > opposite order, but it seems like an odd imposition to put on the > consumers of the code in question. I'm worried that I'm missing > something about the expected semantics of these standard functions. > > -- > Curt Hagenlocher > curt at hagenlocher.org > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From curt at hagenlocher.org Thu Feb 7 00:49:24 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Wed, 6 Feb 2008 15:49:24 -0800 Subject: [IronPython] staticmethod / classmethod and setattr In-Reply-To: <47AA46D9.8080109@voidspace.org.uk> References: <47AA46D9.8080109@voidspace.org.uk> Message-ID: Nice find, thanks. I guess I won't feel so bad about requiring a specific order when defining static methods for "CLR export". On Feb 6, 2008 3:46 PM, Michael Foord wrote: > From http://www.ddj.com/web-development/184406073 > > Usually, most decorators expect a function on input, and return either a > function or an attribute descriptor as their output. The Python > built-ins classmethod, staticmethod, and property all return attribute > descriptors, so their output cannot be passed to a decorator that > expects a function. That's why I had to put classmethod first in Listing > Four. As an experiment, try reversing the order of @traced and > @classmethod in Listing Four, and see if you can guess what will happen. > > > Curt Hagenlocher wrote: > > This is really more of a Python question than an IronPython question, > > but I'm not currently on any non-Iron Python lists. :) > > > > The following definition results in an error under both CPython 2.5 > > and IronPython. Decorating a method as static or class prevents > > attributes being set on the resulting definition. > > > > def decorate(obj): > > obj.decorated = True > > return obj > > > > class X: > > @decorate > > @staticmethod > > def foo(): > > pass > > > > Does anyone know the "why" of this behavior? > > > > I can work around this problem by declaring the decorators in the > > opposite order, but it seems like an odd imposition to put on the > > consumers of the code in question. I'm worried that I'm missing > > something about the expected semantics of these standard functions. > > > > -- > > Curt Hagenlocher > > curt at hagenlocher.org > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael.foord at resolversystems.com Thu Feb 7 11:58:03 2008 From: michael.foord at resolversystems.com (Michael Foord) Date: Thu, 07 Feb 2008 10:58:03 +0000 Subject: [IronPython] HybridMapping is full Error Message-ID: <47AAE43B.1050608@resolversystems.com> Hello, After upgrading to IronPython 1.1.1 we are seeing (sporadically) the following exception when we run our full test suite. Any idea what the cause(s) could be? Unexpected SystemException running tests: System.SystemException: HybridMapping is full at IronPython.Runtime.HybridMapping`1.WeakAdd(T value) at IronPython.Runtime.PythonFile..ctor(Stream stream, Encoding encoding, String mode, Boolean weakMapping) at IronPython.Runtime.PythonFile.Make(ICallerContext context, DynamicType cls, String name, String mode, Int32 bufsize) at IronPython.Runtime.PythonFile.Make(ICallerContext context, DynamicType cls, String name, String mode) at Make##3549(ICallerContext , Object , Object , Object ) at IronPython.Runtime.Calls.FastCallableWithContext3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.FastCallableWithContext3.Call(ICallerContext context, Object[] args) at IronPython.Compiler.MethodBinder.MethodTarget.Call(ICallerContext context, Object[] args) at IronPython.Compiler.MethodBinder.TargetSet.Call(ICallerContext context, CallType callType, Object[] args) at IronPython.Compiler.MethodBinder.TargetSet.Call3(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.FastCallableWithContextAny.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.FastCallableWithContextAny.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Calls.BuiltinFunction.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Types.DynamicType.CreateInstance(ICallerContext con text, Object[] args, String[] names) at IronPython.Runtime.Types.DynamicType.Call(ICallerContext context, Obje ct[] args, String[] names) at IronPython.Runtime.Types.DynamicType.Call(ICallerContext context, Obje ct[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at linecache.updatecache$f105(Object filename) in C:\Dev\buildshare\Resol ver-df367\python24\linecache.py:line 105 at IronPython.Runtime.Calls.Function1.Call(ICallerContext context, Object arg0) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at linecache.getlines$f103(Object filename) in C:\Dev\buildshare\Resolver -df367\python24\linecache.py:line 40 at IronPython.Runtime.Calls.Function1.Call(ICallerContext context, Object arg0) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at linecache.getline$f101(Object filename, Object lineno) in C:\Dev\build share\Resolver-df367\python24\linecache.py:line 14 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at traceback.extract_tb$f89(Object tb, Object limit) in C:\Dev\buildshare \Resolver-df367\python24\traceback.py:line 101 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at traceback.format_tb$f88(Object tb, Object limit) in C:\Dev\buildshare\ Resolver-df367\python24\traceback.py:line 76 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at traceback.format_exception$f91(Object etype, Object value, Object tb, Object limit) in C:\Dev\buildshare\Resolver-df367\python24\traceback.py:line 142 at IronPython.Runtime.Calls.Function4.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1, Object arg2) at unittest._exc_info_to_string$f13(FunctionEnvironment16Dictionary $env, Object self, Object err, Object test) in C:\Dev\buildshare\Resolver-df367\pytho n24\unittest.py:line 153 at IronPython.Runtime.Calls.Function3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at unittest.addError$f8(FunctionEnvironment16Dictionary $env, Object self , Object test, Object err) in C:\Dev\buildshare\Resolver-df367\python24\unittest .py:line 124 at IronPython.Runtime.Calls.Function3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1, Object arg2) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1, Object arg2) at unittest.addError$f72(FunctionEnvironment16Dictionary $env, Object sel f, Object test, Object err) in C:\Dev\buildshare\Resolver-df367\python24\unittes t.py:line 656 at IronPython.Runtime.Calls.Function3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1, Object arg2) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1, Object arg2) at TestUtils.PublishingTestRunner.addError$f2861(FunctionEnvironment16Dic tionary $env, Object self, Object test, Object err) in C:\Dev\buildshare\Resolve r-df367\TestUtils\PublishingTestRunner.py:line 40 at IronPython.Runtime.Calls.Function3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at unittest.run$f26(FunctionEnvironmentNDictionary $env, Object self, Obj ect result) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 255 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at TestUtils.TestCase.run$f252(FunctionEnvironment32Dictionary $env, Obje ct self, Object result) in C:\Dev\buildshare\Resolver-df367\TestUtils\TestCase.p y:line 139 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndCo ntext(ICallerContext context, Object func, Object[] args, String[] names, Object argsTuple, Object kwDict) at unittest.__call__$f27(FunctionEnvironmentNDictionary $env, Object self , Object args, Object kwds) in C:\Dev\buildshare\Resolver-df367\python24\unittes t.py:line 281 at unittest.__call__$f27(FunctionEnvironmentNDictionary , Object[] ) at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) at IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar get, SymbolId name, Object& ret, Object[] args) at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object func, Objec t[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at unittest.run$f44(FunctionEnvironment16Dictionary $env, Object self, Ob ject result) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 429 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndCo ntext(ICallerContext context, Object func, Object[] args, String[] names, Object argsTuple, Object kwDict) at unittest.__call__$f45(FunctionEnvironment16Dictionary $env, Object sel f, Object args, Object kwds) in C:\Dev\buildshare\Resolver-df367\python24\unitte st.py:line 433 at unittest.__call__$f45(FunctionEnvironment16Dictionary , Object[] ) at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) at IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar get, SymbolId name, Object& ret, Object[] args) at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object func, Objec t[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at unittest.run$f44(FunctionEnvironment16Dictionary $env, Object self, Ob ject result) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 429 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndCo ntext(ICallerContext context, Object func, Object[] args, String[] names, Object argsTuple, Object kwDict) at unittest.__call__$f45(FunctionEnvironment16Dictionary $env, Object sel f, Object args, Object kwds) in C:\Dev\buildshare\Resolver-df367\python24\unitte st.py:line 433 at unittest.__call__$f45(FunctionEnvironment16Dictionary , Object[] ) at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) at IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar get, SymbolId name, Object& ret, Object[] args) at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object func, Objec t[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at unittest.run$f78(FunctionEnvironment8Dictionary $env, Object self, Obj ect test) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 701 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object arg0, Object arg1) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at TestUtils.RunTest.RunTest$f1(Object testClass, Object saveResults, Obj ect runs, Object schedule) in C:\Dev\buildshare\Resolver-df367\TestUtils\RunTest .py:line 28 at IronPython.Runtime.HybridMapping`1.WeakAdd(T value) at IronPython.Runtime.PythonFile..ctor(Stream stream, Encoding encoding, String mode, Boolean weakMapping) at IronPython.Runtime.PythonFile.Make(ICallerContext context, DynamicType cls, String name, String mode, Int32 bufsize) at IronPython.Runtime.PythonFile.Make(ICallerContext context, DynamicType cls, String name, String mode) at Make##3549(ICallerContext , Object , Object , Object ) at IronPython.Runtime.Calls.FastCallableWithContext3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.FastCallableWithContext3.Call(ICallerContext context, Object[] args) at IronPython.Compiler.MethodBinder.MethodTarget.Call(ICallerContext cont ext, Object[] args) at IronPython.Compiler.MethodBinder.TargetSet.Call(ICallerContext context , CallType callType, Object[] args) at IronPython.Compiler.MethodBinder.TargetSet.Call3(ICallerContext contex t, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.FastCallableWithContextAny.Call(ICallerContex t context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.FastCallableWithContextAny.Call(ICallerContex t context, Object[] args) at IronPython.Runtime.Calls.BuiltinFunction.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Types.DynamicType.CreateInstance(ICallerContext con text, Object[] args, String[] names) at IronPython.Runtime.Types.DynamicType.Call(ICallerContext context, Obje ct[] args, String[] names) at IronPython.Runtime.Types.DynamicType.Call(ICallerContext context, Obje ct[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at linecache.updatecache$f105(Object filename) in C:\Dev\buildshare\Resol ver-df367\python24\linecache.py:line 105 at IronPython.Runtime.Calls.Function1.Call(ICallerContext context, Object arg0) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at linecache.getlines$f103(Object filename) in C:\Dev\buildshare\Resolver -df367\python24\linecache.py:line 40 at IronPython.Runtime.Calls.Function1.Call(ICallerContext context, Object arg0) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at linecache.getline$f101(Object filename, Object lineno) in C:\Dev\build share\Resolver-df367\python24\linecache.py:line 14 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at traceback.extract_tb$f89(Object tb, Object limit) in C:\Dev\buildshare \Resolver-df367\python24\traceback.py:line 101 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at traceback.format_tb$f88(Object tb, Object limit) in C:\Dev\buildshare\ Resolver-df367\python24\traceback.py:line 76 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at traceback.format_exception$f91(Object etype, Object value, Object tb, Object limit) in C:\Dev\buildshare\Resolver-df367\python24\traceback.py:line 142 at IronPython.Runtime.Calls.Function4.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1, Object arg2) at unittest._exc_info_to_string$f13(FunctionEnvironment16Dictionary $env, Object self, Object err, Object test) in C:\Dev\buildshare\Resolver-df367\pytho n24\unittest.py:line 153 at IronPython.Runtime.Calls.Function3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at unittest.addError$f8(FunctionEnvironment16Dictionary $env, Object self , Object test, Object err) in C:\Dev\buildshare\Resolver-df367\python24\unittest .py:line 124 at IronPython.Runtime.Calls.Function3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1, Object arg2) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1, Object arg2) at unittest.addError$f72(FunctionEnvironment16Dictionary $env, Object sel f, Object test, Object err) in C:\Dev\buildshare\Resolver-df367\python24\unittes t.py:line 656 at IronPython.Runtime.Calls.Function3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1, Object arg2) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1, Object arg2) at TestUtils.PublishingTestRunner.addError$f2861(FunctionEnvironment16Dic tionary $env, Object self, Object test, Object err) in C:\Dev\buildshare\Resolve r-df367\TestUtils\PublishingTestRunner.py:line 40 at IronPython.Runtime.Calls.Function3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at unittest.run$f26(FunctionEnvironmentNDictionary $env, Object self, Obj ect result) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 255 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at TestUtils.TestCase.run$f252(FunctionEnvironment32Dictionary $env, Object self, Object result) in C:\Dev\buildshare\Resolver-df367\TestUtils\TestCase.py:line 139 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndContext(ICallerContext context, Object func, Object[] args, String[] names, Object argsTuple, Object kwDict) at unittest.__call__$f27(FunctionEnvironmentNDictionary $env, Object self , Object args, Object kwds) in C:\Dev\buildshare\Resolver-df367\python24\unittes t.py:line 281 at unittest.__call__$f27(FunctionEnvironmentNDictionary , Object[] ) at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) at IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar get, SymbolId name, Object& ret, Object[] args) at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object func, Objec t[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at unittest.run$f44(FunctionEnvironment16Dictionary $env, Object self, Ob ject result) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 429 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndCo ntext(ICallerContext context, Object func, Object[] args, String[] names, Object argsTuple, Object kwDict) at unittest.__call__$f45(FunctionEnvironment16Dictionary $env, Object sel f, Object args, Object kwds) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 433 at unittest.__call__$f45(FunctionEnvironment16Dictionary , Object[] ) at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) at IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar get, SymbolId name, Object& ret, Object[] args) at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object func, Objec t[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at unittest.run$f44(FunctionEnvironment16Dictionary $env, Object self, Ob ject result) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 429 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndCo ntext(ICallerContext context, Object func, Object[] args, String[] names, Object argsTuple, Object kwDict) at unittest.__call__$f45(FunctionEnvironment16Dictionary $env, Object self, Object args, Object kwds) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 433 at unittest.__call__$f45(FunctionEnvironment16Dictionary , Object[] ) at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) at IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar get, SymbolId name, Object& ret, Object[] args) at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object func, Objec t[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at unittest.run$f78(FunctionEnvironment8Dictionary $env, Object self, Obj ect test) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 701 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object arg0) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext context, Object func, Object arg0) at TestUtils.RunTest.RunTest$f1(Object testClass, Object saveResults, Obj ect runs, Object schedule) in C:\Dev\buildshare\Resolver-df367\TestUtils\RunTest.py:line 28 -- Michael Foord Senior Software Engineer, Resolver Systems Ltd. michael.foord at resolversystems.com +44 (0) 20 7253 6372 We're hiring! http://www.resolversystems.com/jobs/ 17a Clerkenwell Road, London EC1M 5RD, UK VAT No.: GB 893 5643 79 Registered in England and Wales as company number 5467329. Registered address: 843 Finchley Road, London NW11 8NA, UK From curt at hagenlocher.org Thu Feb 7 14:57:08 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Thu, 7 Feb 2008 05:57:08 -0800 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: References: <47A75FA4.5090308@voidspace.org.uk> <47A76257.6090307@voidspace.org.uk> <47A79A3A.8070002@voidspace.org.uk> <47A869B5.8040505@resolversystems.com> <47A8A6E3.1050200@resolversystems.com> Message-ID: I've created a project on CodePlex now. It's still in setup mode; send me email and I'll add you to the project there. The only real change I've made since the Feb 5 version are support for static and class methods. And if the class defines a static or class method named "Main", I set that as the entry point. On Feb 5, 2008 12:00 PM, Curt Hagenlocher wrote: > You can download my work-in-progress from > http://hagenlocher.org/software/ClrWrapper.zip > > The source consists of the three files ClrBuilder.py, ClrWrapper.py and > MakeModule.py. There are also two "demo" files: Xtest.py and WcfServer.py. > The program can currently be run as follows: > > PS F:\IronPython-2.0A8> *.\ipy.exe MakeModule.py Xtest.py* > > This will produce a file called Xtest.dll. > > At this point, the application doesn't require any of the standard Python > library files. It's only been tried with the Alpha 8 binaries -- and in > fact, the hosting interfaces for IronPython still aren't entirely stable so > there's no guarantee that the DLLs produced will work with Alpha 9. > > Xtest.py is a trivial application that implements a single > xunit-compatible unit test > PS F:\IronPython-2.0A8> *.\xunit.console.exe Xtest.dll /noshadow* > . > Total tests: 1, Failures: 0, Skipped: 0, Time: 0.275 seconds > WcfServer.py theoretically implements a WCF server, though I haven't > gotten as far as actually testing the output yet. (The generated > code passes the eyeball compiler.) > > Code quality is unimpressive; your mileage may vary. And I've got to get > back to my "day job" for a few hours now :). > > -- > Curt Hagenlocher > curt at hagenlocher.org > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rpigneri at LavaStorm.com Thu Feb 7 15:55:41 2008 From: rpigneri at LavaStorm.com (Pigneri, Rocco) Date: Thu, 7 Feb 2008 09:55:41 -0500 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF47C9430@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <7AD436E4270DD54A94238001769C2227011CF47C9182@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227011CF47C9430@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: Dino, Thanks for the insight. That helpls a lot. Too bad that we still won't be able to create IP types with the DLR in 2.0. I was hoping that that would be a feature. By the way, do you guys have an idea of when 2.0 final will be released? Or at least an idea of what stages it has left to go through (how many more alpha stages, beta releases, RC's)? I couldn't find this on CodePlex. Thanks, Rocco ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dino Viehland Sent: Wednesday, February 06, 2008 3:54 PM To: Discussion of IronPython Subject: Re: [IronPython] Exporting Python code as an assembly The extra __'s are expected. When we enabled this in 1.1.1 we didn't want to significantly alter the experience between 1.1 and 1.1.1. The problem with 1.1 was that if the caller passed in an attribute to filter by (DataGridView passes in BrowsableAttribute) we would say "attributes? We don't have attributes, so you'll get an empty collection". In 1.1.1 we'll return just about anything if browsable is set. In 2.0, where we have a little more leeway to change things, we're more aggressive about filtering out things you probably don't want to see. You can always not auto-generate the columns and you'll get the columns you presumably want. The AllowNew is going to be an unfortunate limitation - Python type instances can't (easily) be created by anyone except for the Python runtime. The reason is we need to pass a PythonType object into the contructor so the object knows it's type in the Python world. So we probably can't do much about this one L. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Pigneri, Rocco Sent: Wednesday, February 06, 2008 12:47 PM To: Discussion of IronPython Subject: Re: [IronPython] Exporting Python code as an assembly Dino, Ah ha! Well, it didn't work under 1.1, but under 1.1.1, it worked nearly right out of the box. When I used a static interface under 1.1, I only got the static properties in the DataGridView. However, under 1.1.1, I am getting a whole extra slew of information in my Grids (__weakref__, __doc__, the hidden values, the properties themselves, every function in the type) when I turn on AutoColumnGenerate. Is this what I should be expecting? Also, it seems that if I turn on user creation of new elements (BindingList.AllowNew = True), then the component crashes with an error stating that it cannot find the constructor for my type, whether or not I have defined it. Is this also to be expected or not? Thank you, Rocco Pigneri ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dino Viehland Sent: Tuesday, February 05, 2008 4:55 PM To: Discussion of IronPython Subject: Re: [IronPython] Exporting Python code as an assembly Data binding isn't working for you? We have support for this via CustomTypeDescriptors which describe the Python objects and we have some test cases to verify it works. Note it was broken before 1.1.1 although it's been working in 2.0 for a little while now. For example: import clr clr.AddReference('System.Windows.Forms') import System.Windows.Forms as SWF import System class AgeQualifier(object): def __get__(self, instance, ctx): if instance.Age < 13: return 'young' if instance.Age < 20: return 'teen' if instance.Age < 30: return 'twenties' if instance.Age < 40: return 'thirties' if instance.Age < 50: return 'forties' return 'old' SAMPLE_DATA = [('Joe', 23, 'twenties'), ('Bob', 8, 'young'), ('Thomas', 32, 'thirties'), ('Patrick', 41, 'forties'), ('Kathy', 19, 'teen'), ('Sue' , 77, 'old'),] class Person(System.Object): def __init__(self, name, age): self._name = name self._age = age def get_name(self): return self._name def set_name(self, value): self._name = value Name = property(get_name, set_name) def get_age(self): return self._age def set_age(self, value): self._age = value Age = property(get_age, set_age) AgeDescription = AgeQualifier() class Form(SWF.Form): def __init__(self): SWF.Form.__init__(self) self._people = people = [] for name, age, ignored in SAMPLE_DATA: people.append(Person(name, age)) grid = SWF.DataGridView() grid.AutoGenerateColumns = True grid.DataSource = people grid.Dock = SWF.DockStyle.Fill self.grid = grid self.Controls.Add(grid) form = Form() SWF.Application.Run(form) From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Pigneri, Rocco Sent: Tuesday, February 05, 2008 9:15 AM To: Discussion of IronPython Subject: Re: [IronPython] Exporting Python code as an assembly Curt, This is a great feature and was one of the first features that I investigated when I first got my hands on IP. I see an immediate need for this feature in using data binding with Windows Forms controls. Many controls (such as DataGridView and ListView) reflect over the properties of bound objects in order to display this data dynamically with no programmer setup. Because IP types are dynamic, WinForms cannot find any properties to bind and creates an "empty" object. In order to use these features now, I must create static interfaces with the required properties in a separate assembly and then inherit that interface whenever I bind to business objects. To make using these UI controls easier, it would be great if property statements could be turned into static properties either automatically or via a flag. It seems that IP already matches properties to the correct static getter/setter as defined in the interfaces so this should be a reasonable request. This staticization would remove the need for the separate static interface. Another situation in which this would be really helpful--although less critical--involves situations where I want to use a static tool on an IP assembly (for example, I want to use NUnit to test my IP classes). I say that this is not critical as a lot of tools already have Python-specific versions available--PyUnit is a good example. Finally, would there be a way to simplify programmer work by providing "standard" static creators that are turned on and off at a high level? For example, programmers could use a "compiler" switch to turn all functions into "void func(object, . . .)" and "object func(obj. . . )". I see this being useful in situations such as using NUnit because all that is really needed is the proper number of arguments and the right function name (all of which are already known in Python). If things then work the way that I think they work, you could then just pass the objects into the correct comparators, and if they are the right type, then the tests will run. Otherwise, you'll get an exception. Hope that helps, Rocco ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Monday, February 04, 2008 1:31 PM To: Discussion of IronPython Subject: [IronPython] Exporting Python code as an assembly After a bit of spare-time hacking this weekend, I've got a "proof-of-concept" program that takes a Python class and exports it as a (statically-defined) assembly. It uses Pythonic function annotations to signal attributes and input and output types to the wrapper generator. You end up with something like this def Test(object): @ClrAttribute(Xunit.FactAttribute) def WorthlessTest(self): Xunit.Assert.Equal[type(1)](1, 1) @ClrAccepts(System.String, System.Int32) @ClrReturns(System.Int32) def CalculateValue(self, s, i): return len(s) + i The program takes this source and spits out a DLL containing the class "Test" which implements "WorthlessTest" and "CalculateValue". The class itself contains a reference to the actual Python object, and each of the public functions simply delegates to the Pythonic implementation. I'm still working on cleaning up the source a little before releasing it, but was wondering if anyone had some feedback on the design as described so far. What should be changed or implemented in order for this to be more useful to you? Thanks, -Curt -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at voidspace.org.uk Thu Feb 7 16:19:07 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Thu, 07 Feb 2008 15:19:07 +0000 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: References: <7AD436E4270DD54A94238001769C2227011CF47C9182@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227011CF47C9430@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <47AB216B.8060108@voidspace.org.uk> Pigneri, Rocco wrote: > Dino, > Thanks for the insight. That helpls a lot. Too bad that we still won't > be able to create IP types with the DLR in 2.0. I was hoping that that > would be a feature. > Did you see this article on future CLR/DLR integration? http://blogs.msdn.com/charlie/archive/2008/01/25/future-focus.aspx > By the way, do you guys have an idea of when 2.0 final will be > released? Or at least an idea of what stages it has left to go through > (how many more alpha stages, beta releases, RC's)? I couldn't find > this on CodePlex. 'They' did say, not long ago, that IP 2 final would be sometime around the end of this year and *hopefully* coincide with a DLR 1.0 final. Michael http://www.manning.com/foord > Thanks, > Rocco > > ------------------------------------------------------------------------ > *From:* users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] *On Behalf Of *Dino Viehland > *Sent:* Wednesday, February 06, 2008 3:54 PM > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] Exporting Python code as an assembly > > The extra __?s are expected. When we enabled this in 1.1.1 we didn?t > want to significantly alter the experience between 1.1 and 1.1.1. The > problem with 1.1 was that if the caller passed in an attribute to > filter by (DataGridView passes in BrowsableAttribute) we would say > ?attributes? We don?t have attributes, so you?ll get an empty > collection?. In 1.1.1 we?ll return just about anything if browsable is > set. In 2.0, where we have a little more leeway to change things, > we?re more aggressive about filtering out things you probably don?t > want to see. You can always not auto-generate the columns and you?ll > get the columns you presumably want. > > The AllowNew is going to be an unfortunate limitation ? Python type > instances can?t (easily) be created by anyone except for the Python > runtime. The reason is we need to pass a PythonType object into the > contructor so the object knows it?s type in the Python world. So we > probably can?t do much about this one L. > > *From:* users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] *On Behalf Of *Pigneri, Rocco > *Sent:* Wednesday, February 06, 2008 12:47 PM > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] Exporting Python code as an assembly > > Dino, > > Ah ha! Well, it didn't work under 1.1, but under 1.1.1, it worked > nearly right out of the box. When I used a static interface under 1.1, > I only got the static properties in the DataGridView. However, under > 1.1.1, I am getting a whole extra slew of information in my Grids > (__weakref__, __doc__, the hidden values, the properties themselves, > every function in the type) when I turn on AutoColumnGenerate. Is this > what I should be expecting? > > Also, it seems that if I turn on user creation of new elements > (BindingList.AllowNew = True), then the component crashes with an > error stating that it cannot find the constructor for my type, whether > or not I have defined it. Is this also to be expected or not? > > Thank you, > > Rocco Pigneri > > ------------------------------------------------------------------------ > > *From:* users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] *On Behalf Of *Dino Viehland > *Sent:* Tuesday, February 05, 2008 4:55 PM > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] Exporting Python code as an assembly > > Data binding isn?t working for you? We have support for this via > CustomTypeDescriptors which describe the Python objects and we have > some test cases to verify it works. Note it was broken before 1.1.1 > although it?s been working in 2.0 for a little while now. For example: > > import clr > > clr.AddReference('System.Windows.Forms') > > import System.Windows.Forms as SWF > > import System > > class AgeQualifier(object): > > def __get__(self, instance, ctx): > > if instance.Age < 13: return 'young' > > if instance.Age < 20: return 'teen' > > if instance.Age < 30: return 'twenties' > > if instance.Age < 40: return 'thirties' > > if instance.Age < 50: return 'forties' > > return 'old' > > SAMPLE_DATA = [('Joe', 23, 'twenties'), ('Bob', 8, 'young'), > ('Thomas', 32, 'thirties'), ('Patrick', 41, 'forties'), ('Kathy', 19, > 'teen'), ('Sue' , 77, 'old'),] > > class Person(System.Object): > > def __init__(self, name, age): > > self._name = name > > self._age = age > > def get_name(self): > > return self._name > > def set_name(self, value): > > self._name = value > > Name = property(get_name, set_name) > > def get_age(self): > > return self._age > > def set_age(self, value): > > self._age = value > > Age = property(get_age, set_age) > > AgeDescription = AgeQualifier() > > class Form(SWF.Form): > > def __init__(self): > > SWF.Form.__init__(self) > > self._people = people = [] > > for name, age, ignored in SAMPLE_DATA: > > people.append(Person(name, age)) > > grid = SWF.DataGridView() > > grid.AutoGenerateColumns = True > > grid.DataSource = people > > grid.Dock = SWF.DockStyle.Fill > > self.grid = grid > > self.Controls.Add(grid) > > form = Form() > > SWF.Application.Run(form) > > *From:* users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] *On Behalf Of *Pigneri, Rocco > *Sent:* Tuesday, February 05, 2008 9:15 AM > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] Exporting Python code as an assembly > > Curt, > > This is a great feature and was one of the first features that I > investigated when I first got my hands on IP. > > I see an immediate need for this feature in using data binding with > Windows Forms controls. Many controls (such as DataGridView and > ListView) reflect over the properties of bound objects in order to > display this data dynamically with no programmer setup. Because IP > types are dynamic, WinForms cannot find any properties to bind and > creates an "empty" object. In order to use these features now, I must > create static interfaces with the required properties in a separate > assembly and then inherit that interface whenever I bind to business > objects. > > To make using these UI controls easier, it would be great if property > statements could be turned into static properties either automatically > or via a flag. It seems that IP already matches properties to the > correct static getter/setter as defined in the interfaces so this > should be a reasonable request. This staticization would remove the > need for the separate static interface. > > Another situation in which this would be really helpful--although less > critical--involves situations where I want to use a static tool on an > IP assembly (for example, I want to use NUnit to test my IP classes). > I say that this is not critical as a lot of tools already have > Python-specific versions available--PyUnit is a good example. > > Finally, would there be a way to simplify programmer work by providing > "standard" static creators that are turned on and off at a high level? > For example, programmers could use a "compiler" switch to turn all > functions into "void func(object, . . .)" and "object func(obj. . . > )". I see this being useful in situations such as using NUnit because > all that is really needed is the proper number of arguments and the > right function name (all of which are already known in Python). If > things then work the way that I think they work, you could then just > pass the objects into the correct comparators, and if they are the > right type, then the tests will run. Otherwise, you'll get an exception. > > Hope that helps, > > Rocco > > ------------------------------------------------------------------------ > > *From:* users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] *On Behalf Of *Curt > Hagenlocher > *Sent:* Monday, February 04, 2008 1:31 PM > *To:* Discussion of IronPython > *Subject:* [IronPython] Exporting Python code as an assembly > > After a bit of spare-time hacking this weekend, I've got a > "proof-of-concept" program that takes a Python class and exports it as > a (statically-defined) assembly. It uses Pythonic function annotations > to signal attributes and input and output types to the wrapper > generator. You end up with something like this > > def Test(object): > > @ClrAttribute(Xunit.FactAttribute) > > def WorthlessTest(self): > > Xunit.Assert.Equal[type(1)](1, 1) > > @ClrAccepts(System.String, System.Int32) > > @ClrReturns(System.Int32) > > def CalculateValue(self, s, i): > > return len(s) + i > > The program takes this source and spits out a DLL containing the class > "Test" which implements "WorthlessTest" and "CalculateValue". The > class itself contains a reference to the actual Python object, and > each of the public functions simply delegates to the Pythonic > implementation. > > I'm still working on cleaning up the source a little before releasing > it, but was wondering if anyone had some feedback on the design as > described so far. What should be changed or implemented in order for > this to be more useful to you? > > Thanks, > > -Curt > > -- > > Curt Hagenlocher > > curt at hagenlocher.org > > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From rpigneri at LavaStorm.com Thu Feb 7 16:44:21 2008 From: rpigneri at LavaStorm.com (Pigneri, Rocco) Date: Thu, 7 Feb 2008 10:44:21 -0500 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: <47AB216B.8060108@voidspace.org.uk> References: <7AD436E4270DD54A94238001769C2227011CF47C9182@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227011CF47C9430@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47AB216B.8060108@voidspace.org.uk> Message-ID: Michael, >Pigneri, Rocco wrote: >> Dino, >> Thanks for the insight. That helpls a lot. Too bad that we still won't >> be able to create IP types with the DLR in 2.0. I was hoping that that >> would be a feature. >> >Did you see this article on future CLR/DLR integration? > >http://blogs.msdn.com/charlie/archive/2008/01/25/future-focus.aspx I actually had, and I saw this written in the last paragraph of the Scenarios section: "C# developers can currently use reflection to instantiate classes and call arbitrary methods that are not known at compile time. The dynamic extensions to the C# language will make it much easier to make such calls." It sounded like this would allow C# developers to "new up" an instance of an IPy object, but this contradicts everything that I had heard on this list. So I just assumed that I misread this statement :-). Then when I found out that IPY 1.1.1 supports "staticizing" properties for data binding, I thought that maybe I was wrong and that it could also support the AllowNew option. I was wrong :-). >> By the way, do you guys have an idea of when 2.0 final will be >> released? Or at least an idea of what stages it has left to go through >> (how many more alpha stages, beta releases, RC's)? I couldn't find >> this on CodePlex. >'They' did say, not long ago, that IP 2 final would be sometime around the end of this year and *hopefully* coincide with a DLR 1.0 final. You know what, they probably did, and I probably don't remember :-)! I have been learning so much in the last month and a half (IPY, Python itself, IPY Studio, DLR, CLR) that it probably got crowded out by all the other things running through my mind :-). Thank you, Rocco -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: Thursday, February 07, 2008 10:19 AM To: Discussion of IronPython Subject: Re: [IronPython] Exporting Python code as an assembly Pigneri, Rocco wrote: > Dino, > Thanks for the insight. That helpls a lot. Too bad that we still won't > be able to create IP types with the DLR in 2.0. I was hoping that that > would be a feature. > Did you see this article on future CLR/DLR integration? http://blogs.msdn.com/charlie/archive/2008/01/25/future-focus.aspx > By the way, do you guys have an idea of when 2.0 final will be > released? Or at least an idea of what stages it has left to go through > (how many more alpha stages, beta releases, RC's)? I couldn't find > this on CodePlex. 'They' did say, not long ago, that IP 2 final would be sometime around the end of this year and *hopefully* coincide with a DLR 1.0 final. Michael http://www.manning.com/foord > Thanks, > Rocco > > ---------------------------------------------------------------------- > -- > *From:* users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] *On Behalf Of *Dino > Viehland > *Sent:* Wednesday, February 06, 2008 3:54 PM > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] Exporting Python code as an assembly > > The extra __'s are expected. When we enabled this in 1.1.1 we didn't > want to significantly alter the experience between 1.1 and 1.1.1. The > problem with 1.1 was that if the caller passed in an attribute to > filter by (DataGridView passes in BrowsableAttribute) we would say > "attributes? We don't have attributes, so you'll get an empty > collection". In 1.1.1 we'll return just about anything if browsable is > set. In 2.0, where we have a little more leeway to change things, > we're more aggressive about filtering out things you probably don't > want to see. You can always not auto-generate the columns and you'll > get the columns you presumably want. > > The AllowNew is going to be an unfortunate limitation - Python type > instances can't (easily) be created by anyone except for the Python > runtime. The reason is we need to pass a PythonType object into the > contructor so the object knows it's type in the Python world. So we > probably can't do much about this one L. > > *From:* users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] *On Behalf Of *Pigneri, > Rocco > *Sent:* Wednesday, February 06, 2008 12:47 PM > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] Exporting Python code as an assembly > > Dino, > > Ah ha! Well, it didn't work under 1.1, but under 1.1.1, it worked > nearly right out of the box. When I used a static interface under 1.1, > I only got the static properties in the DataGridView. However, under > 1.1.1, I am getting a whole extra slew of information in my Grids > (__weakref__, __doc__, the hidden values, the properties themselves, > every function in the type) when I turn on AutoColumnGenerate. Is this > what I should be expecting? > > Also, it seems that if I turn on user creation of new elements > (BindingList.AllowNew = True), then the component crashes with an > error stating that it cannot find the constructor for my type, whether > or not I have defined it. Is this also to be expected or not? > > Thank you, > > Rocco Pigneri > > ---------------------------------------------------------------------- > -- > > *From:* users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] *On Behalf Of *Dino > Viehland > *Sent:* Tuesday, February 05, 2008 4:55 PM > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] Exporting Python code as an assembly > > Data binding isn't working for you? We have support for this via > CustomTypeDescriptors which describe the Python objects and we have > some test cases to verify it works. Note it was broken before 1.1.1 > although it's been working in 2.0 for a little while now. For example: > > import clr > > clr.AddReference('System.Windows.Forms') > > import System.Windows.Forms as SWF > > import System > > class AgeQualifier(object): > > def __get__(self, instance, ctx): > > if instance.Age < 13: return 'young' > > if instance.Age < 20: return 'teen' > > if instance.Age < 30: return 'twenties' > > if instance.Age < 40: return 'thirties' > > if instance.Age < 50: return 'forties' > > return 'old' > > SAMPLE_DATA = [('Joe', 23, 'twenties'), ('Bob', 8, 'young'), > ('Thomas', 32, 'thirties'), ('Patrick', 41, 'forties'), ('Kathy', 19, > 'teen'), ('Sue' , 77, 'old'),] > > class Person(System.Object): > > def __init__(self, name, age): > > self._name = name > > self._age = age > > def get_name(self): > > return self._name > > def set_name(self, value): > > self._name = value > > Name = property(get_name, set_name) > > def get_age(self): > > return self._age > > def set_age(self, value): > > self._age = value > > Age = property(get_age, set_age) > > AgeDescription = AgeQualifier() > > class Form(SWF.Form): > > def __init__(self): > > SWF.Form.__init__(self) > > self._people = people = [] > > for name, age, ignored in SAMPLE_DATA: > > people.append(Person(name, age)) > > grid = SWF.DataGridView() > > grid.AutoGenerateColumns = True > > grid.DataSource = people > > grid.Dock = SWF.DockStyle.Fill > > self.grid = grid > > self.Controls.Add(grid) > > form = Form() > > SWF.Application.Run(form) > > *From:* users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] *On Behalf Of *Pigneri, > Rocco > *Sent:* Tuesday, February 05, 2008 9:15 AM > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] Exporting Python code as an assembly > > Curt, > > This is a great feature and was one of the first features that I > investigated when I first got my hands on IP. > > I see an immediate need for this feature in using data binding with > Windows Forms controls. Many controls (such as DataGridView and > ListView) reflect over the properties of bound objects in order to > display this data dynamically with no programmer setup. Because IP > types are dynamic, WinForms cannot find any properties to bind and > creates an "empty" object. In order to use these features now, I must > create static interfaces with the required properties in a separate > assembly and then inherit that interface whenever I bind to business > objects. > > To make using these UI controls easier, it would be great if property > statements could be turned into static properties either automatically > or via a flag. It seems that IP already matches properties to the > correct static getter/setter as defined in the interfaces so this > should be a reasonable request. This staticization would remove the > need for the separate static interface. > > Another situation in which this would be really helpful--although less > critical--involves situations where I want to use a static tool on an > IP assembly (for example, I want to use NUnit to test my IP classes). > I say that this is not critical as a lot of tools already have > Python-specific versions available--PyUnit is a good example. > > Finally, would there be a way to simplify programmer work by providing > "standard" static creators that are turned on and off at a high level? > For example, programmers could use a "compiler" switch to turn all > functions into "void func(object, . . .)" and "object func(obj. . . > )". I see this being useful in situations such as using NUnit because > all that is really needed is the proper number of arguments and the > right function name (all of which are already known in Python). If > things then work the way that I think they work, you could then just > pass the objects into the correct comparators, and if they are the > right type, then the tests will run. Otherwise, you'll get an exception. > > Hope that helps, > > Rocco > > ---------------------------------------------------------------------- > -- > > *From:* users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] *On Behalf Of *Curt > Hagenlocher > *Sent:* Monday, February 04, 2008 1:31 PM > *To:* Discussion of IronPython > *Subject:* [IronPython] Exporting Python code as an assembly > > After a bit of spare-time hacking this weekend, I've got a > "proof-of-concept" program that takes a Python class and exports it as > a (statically-defined) assembly. It uses Pythonic function annotations > to signal attributes and input and output types to the wrapper > generator. You end up with something like this > > def Test(object): > > @ClrAttribute(Xunit.FactAttribute) > > def WorthlessTest(self): > > Xunit.Assert.Equal[type(1)](1, 1) > > @ClrAccepts(System.String, System.Int32) > > @ClrReturns(System.Int32) > > def CalculateValue(self, s, i): > > return len(s) + i > > The program takes this source and spits out a DLL containing the class > "Test" which implements "WorthlessTest" and "CalculateValue". The > class itself contains a reference to the actual Python object, and > each of the public functions simply delegates to the Pythonic > implementation. > > I'm still working on cleaning up the source a little before releasing > it, but was wondering if anyone had some feedback on the design as > described so far. What should be changed or implemented in order for > this to be more useful to you? > > Thanks, > > -Curt > > -- > > Curt Hagenlocher > > curt at hagenlocher.org > > ---------------------------------------------------------------------- > -- > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From dinov at exchange.microsoft.com Thu Feb 7 17:32:43 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Thu, 7 Feb 2008 08:32:43 -0800 Subject: [IronPython] HybridMapping is full Error In-Reply-To: <47AAE43B.1050608@resolversystems.com> References: <47AAE43B.1050608@resolversystems.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF47C95C0@DF-GRTDANE-MSG.exchange.corp.microsoft.com> It looks like there's an internal limit that prevents us from ever having more than 4096 PythonFile objects in existance. Is it possible that you have that many file objects in existence that aren't getting freed? Also just closing them won't be enough, they actually have to get collected by the GC. I don't think anything has actually changed here between 1.1 and 1.1.1 so it might just be hitting slightly different lifetimes. But this limit does seem pretty stupid (and it's still in 2.0 as well apparently :( ). -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: Thursday, February 07, 2008 2:58 AM To: Discussion of IronPython Subject: [IronPython] HybridMapping is full Error Hello, After upgrading to IronPython 1.1.1 we are seeing (sporadically) the following exception when we run our full test suite. Any idea what the cause(s) could be? Unexpected SystemException running tests: System.SystemException: HybridMapping is full at IronPython.Runtime.HybridMapping`1.WeakAdd(T value) at IronPython.Runtime.PythonFile..ctor(Stream stream, Encoding encoding, String mode, Boolean weakMapping) at IronPython.Runtime.PythonFile.Make(ICallerContext context, DynamicType cls, String name, String mode, Int32 bufsize) at IronPython.Runtime.PythonFile.Make(ICallerContext context, DynamicType cls, String name, String mode) at Make##3549(ICallerContext , Object , Object , Object ) at IronPython.Runtime.Calls.FastCallableWithContext3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.FastCallableWithContext3.Call(ICallerContext context, Object[] args) at IronPython.Compiler.MethodBinder.MethodTarget.Call(ICallerContext context, Object[] args) at IronPython.Compiler.MethodBinder.TargetSet.Call(ICallerContext context, CallType callType, Object[] args) at IronPython.Compiler.MethodBinder.TargetSet.Call3(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.FastCallableWithContextAny.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.FastCallableWithContextAny.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Calls.BuiltinFunction.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Types.DynamicType.CreateInstance(ICallerContext con text, Object[] args, String[] names) at IronPython.Runtime.Types.DynamicType.Call(ICallerContext context, Obje ct[] args, String[] names) at IronPython.Runtime.Types.DynamicType.Call(ICallerContext context, Obje ct[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at linecache.updatecache$f105(Object filename) in C:\Dev\buildshare\Resol ver-df367\python24\linecache.py:line 105 at IronPython.Runtime.Calls.Function1.Call(ICallerContext context, Object arg0) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at linecache.getlines$f103(Object filename) in C:\Dev\buildshare\Resolver -df367\python24\linecache.py:line 40 at IronPython.Runtime.Calls.Function1.Call(ICallerContext context, Object arg0) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at linecache.getline$f101(Object filename, Object lineno) in C:\Dev\build share\Resolver-df367\python24\linecache.py:line 14 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at traceback.extract_tb$f89(Object tb, Object limit) in C:\Dev\buildshare \Resolver-df367\python24\traceback.py:line 101 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at traceback.format_tb$f88(Object tb, Object limit) in C:\Dev\buildshare\ Resolver-df367\python24\traceback.py:line 76 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at traceback.format_exception$f91(Object etype, Object value, Object tb, Object limit) in C:\Dev\buildshare\Resolver-df367\python24\traceback.py:line 142 at IronPython.Runtime.Calls.Function4.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1, Object arg2) at unittest._exc_info_to_string$f13(FunctionEnvironment16Dictionary $env, Object self, Object err, Object test) in C:\Dev\buildshare\Resolver-df367\pytho n24\unittest.py:line 153 at IronPython.Runtime.Calls.Function3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at unittest.addError$f8(FunctionEnvironment16Dictionary $env, Object self , Object test, Object err) in C:\Dev\buildshare\Resolver-df367\python24\unittest .py:line 124 at IronPython.Runtime.Calls.Function3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1, Object arg2) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1, Object arg2) at unittest.addError$f72(FunctionEnvironment16Dictionary $env, Object sel f, Object test, Object err) in C:\Dev\buildshare\Resolver-df367\python24\unittes t.py:line 656 at IronPython.Runtime.Calls.Function3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1, Object arg2) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1, Object arg2) at TestUtils.PublishingTestRunner.addError$f2861(FunctionEnvironment16Dic tionary $env, Object self, Object test, Object err) in C:\Dev\buildshare\Resolve r-df367\TestUtils\PublishingTestRunner.py:line 40 at IronPython.Runtime.Calls.Function3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at unittest.run$f26(FunctionEnvironmentNDictionary $env, Object self, Obj ect result) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 255 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at TestUtils.TestCase.run$f252(FunctionEnvironment32Dictionary $env, Obje ct self, Object result) in C:\Dev\buildshare\Resolver-df367\TestUtils\TestCase.p y:line 139 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndCo ntext(ICallerContext context, Object func, Object[] args, String[] names, Object argsTuple, Object kwDict) at unittest.__call__$f27(FunctionEnvironmentNDictionary $env, Object self , Object args, Object kwds) in C:\Dev\buildshare\Resolver-df367\python24\unittes t.py:line 281 at unittest.__call__$f27(FunctionEnvironmentNDictionary , Object[] ) at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) at IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar get, SymbolId name, Object& ret, Object[] args) at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object func, Objec t[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at unittest.run$f44(FunctionEnvironment16Dictionary $env, Object self, Ob ject result) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 429 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndCo ntext(ICallerContext context, Object func, Object[] args, String[] names, Object argsTuple, Object kwDict) at unittest.__call__$f45(FunctionEnvironment16Dictionary $env, Object sel f, Object args, Object kwds) in C:\Dev\buildshare\Resolver-df367\python24\unitte st.py:line 433 at unittest.__call__$f45(FunctionEnvironment16Dictionary , Object[] ) at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) at IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar get, SymbolId name, Object& ret, Object[] args) at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object func, Objec t[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at unittest.run$f44(FunctionEnvironment16Dictionary $env, Object self, Ob ject result) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 429 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndCo ntext(ICallerContext context, Object func, Object[] args, String[] names, Object argsTuple, Object kwDict) at unittest.__call__$f45(FunctionEnvironment16Dictionary $env, Object sel f, Object args, Object kwds) in C:\Dev\buildshare\Resolver-df367\python24\unitte st.py:line 433 at unittest.__call__$f45(FunctionEnvironment16Dictionary , Object[] ) at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) at IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar get, SymbolId name, Object& ret, Object[] args) at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object func, Objec t[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at unittest.run$f78(FunctionEnvironment8Dictionary $env, Object self, Obj ect test) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 701 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object arg0, Object arg1) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at TestUtils.RunTest.RunTest$f1(Object testClass, Object saveResults, Obj ect runs, Object schedule) in C:\Dev\buildshare\Resolver-df367\TestUtils\RunTest .py:line 28 at IronPython.Runtime.HybridMapping`1.WeakAdd(T value) at IronPython.Runtime.PythonFile..ctor(Stream stream, Encoding encoding, String mode, Boolean weakMapping) at IronPython.Runtime.PythonFile.Make(ICallerContext context, DynamicType cls, String name, String mode, Int32 bufsize) at IronPython.Runtime.PythonFile.Make(ICallerContext context, DynamicType cls, String name, String mode) at Make##3549(ICallerContext , Object , Object , Object ) at IronPython.Runtime.Calls.FastCallableWithContext3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.FastCallableWithContext3.Call(ICallerContext context, Object[] args) at IronPython.Compiler.MethodBinder.MethodTarget.Call(ICallerContext cont ext, Object[] args) at IronPython.Compiler.MethodBinder.TargetSet.Call(ICallerContext context , CallType callType, Object[] args) at IronPython.Compiler.MethodBinder.TargetSet.Call3(ICallerContext contex t, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.FastCallableWithContextAny.Call(ICallerContex t context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.FastCallableWithContextAny.Call(ICallerContex t context, Object[] args) at IronPython.Runtime.Calls.BuiltinFunction.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Types.DynamicType.CreateInstance(ICallerContext con text, Object[] args, String[] names) at IronPython.Runtime.Types.DynamicType.Call(ICallerContext context, Obje ct[] args, String[] names) at IronPython.Runtime.Types.DynamicType.Call(ICallerContext context, Obje ct[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at linecache.updatecache$f105(Object filename) in C:\Dev\buildshare\Resol ver-df367\python24\linecache.py:line 105 at IronPython.Runtime.Calls.Function1.Call(ICallerContext context, Object arg0) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at linecache.getlines$f103(Object filename) in C:\Dev\buildshare\Resolver -df367\python24\linecache.py:line 40 at IronPython.Runtime.Calls.Function1.Call(ICallerContext context, Object arg0) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at linecache.getline$f101(Object filename, Object lineno) in C:\Dev\build share\Resolver-df367\python24\linecache.py:line 14 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at traceback.extract_tb$f89(Object tb, Object limit) in C:\Dev\buildshare \Resolver-df367\python24\traceback.py:line 101 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at traceback.format_tb$f88(Object tb, Object limit) in C:\Dev\buildshare\ Resolver-df367\python24\traceback.py:line 76 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at traceback.format_exception$f91(Object etype, Object value, Object tb, Object limit) in C:\Dev\buildshare\Resolver-df367\python24\traceback.py:line 142 at IronPython.Runtime.Calls.Function4.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1, Object arg2) at unittest._exc_info_to_string$f13(FunctionEnvironment16Dictionary $env, Object self, Object err, Object test) in C:\Dev\buildshare\Resolver-df367\pytho n24\unittest.py:line 153 at IronPython.Runtime.Calls.Function3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at unittest.addError$f8(FunctionEnvironment16Dictionary $env, Object self , Object test, Object err) in C:\Dev\buildshare\Resolver-df367\python24\unittest .py:line 124 at IronPython.Runtime.Calls.Function3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1, Object arg2) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1, Object arg2) at unittest.addError$f72(FunctionEnvironment16Dictionary $env, Object sel f, Object test, Object err) in C:\Dev\buildshare\Resolver-df367\python24\unittes t.py:line 656 at IronPython.Runtime.Calls.Function3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1, Object arg2) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1, Object arg2) at TestUtils.PublishingTestRunner.addError$f2861(FunctionEnvironment16Dic tionary $env, Object self, Object test, Object err) in C:\Dev\buildshare\Resolve r-df367\TestUtils\PublishingTestRunner.py:line 40 at IronPython.Runtime.Calls.Function3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at unittest.run$f26(FunctionEnvironmentNDictionary $env, Object self, Obj ect result) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 255 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object ar g0, Object arg1) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0, Object arg1) at TestUtils.TestCase.run$f252(FunctionEnvironment32Dictionary $env, Object self, Object result) in C:\Dev\buildshare\Resolver-df367\TestUtils\TestCase.py:line 139 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndContext(ICallerContext context, Object func, Object[] args, String[] names, Object argsTuple, Object kwDict) at unittest.__call__$f27(FunctionEnvironmentNDictionary $env, Object self , Object args, Object kwds) in C:\Dev\buildshare\Resolver-df367\python24\unittes t.py:line 281 at unittest.__call__$f27(FunctionEnvironmentNDictionary , Object[] ) at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) at IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar get, SymbolId name, Object& ret, Object[] args) at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object func, Objec t[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at unittest.run$f44(FunctionEnvironment16Dictionary $env, Object self, Ob ject result) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 429 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndCo ntext(ICallerContext context, Object func, Object[] args, String[] names, Object argsTuple, Object kwDict) at unittest.__call__$f45(FunctionEnvironment16Dictionary $env, Object sel f, Object args, Object kwds) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 433 at unittest.__call__$f45(FunctionEnvironment16Dictionary , Object[] ) at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) at IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar get, SymbolId name, Object& ret, Object[] args) at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object func, Objec t[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at unittest.run$f44(FunctionEnvironment16Dictionary $env, Object self, Ob ject result) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 429 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndCo ntext(ICallerContext context, Object func, Object[] args, String[] names, Object argsTuple, Object kwDict) at unittest.__call__$f45(FunctionEnvironment16Dictionary $env, Object self, Object args, Object kwds) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 433 at unittest.__call__$f45(FunctionEnvironment16Dictionary , Object[] ) at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext context, Object [] args) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co ntext, Object instance, Object[] args) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object[] args) at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) at IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar get, SymbolId name, Object& ret, Object[] args) at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object func, Objec t[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object[] args) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte xt, Object func, Object arg0) at unittest.run$f78(FunctionEnvironment8Dictionary $env, Object self, Obj ect test) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 701 at IronPython.Runtime.Calls.Function2.Call(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext context, Object arg0, Object arg1) at IronPython.Runtime.Calls.Method.Call(ICallerContext context, Object arg0) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext context, Object func, Object arg0) at TestUtils.RunTest.RunTest$f1(Object testClass, Object saveResults, Obj ect runs, Object schedule) in C:\Dev\buildshare\Resolver-df367\TestUtils\RunTest.py:line 28 -- Michael Foord Senior Software Engineer, Resolver Systems Ltd. michael.foord at resolversystems.com +44 (0) 20 7253 6372 We're hiring! http://www.resolversystems.com/jobs/ 17a Clerkenwell Road, London EC1M 5RD, UK VAT No.: GB 893 5643 79 Registered in England and Wales as company number 5467329. Registered address: 843 Finchley Road, London NW11 8NA, UK _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From dinov at exchange.microsoft.com Thu Feb 7 17:37:16 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Thu, 7 Feb 2008 08:37:16 -0800 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: References: <7AD436E4270DD54A94238001769C2227011CF47C9182@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227011CF47C9430@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF47C95C5@DF-GRTDANE-MSG.exchange.corp.microsoft.com> We're planning on shipping 2.0 RTM sometime in the 2nd half of this year - but we don't have a firm date quite yet. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Pigneri, Rocco Sent: Thursday, February 07, 2008 6:56 AM To: Discussion of IronPython Subject: Re: [IronPython] Exporting Python code as an assembly Dino, Thanks for the insight. That helpls a lot. Too bad that we still won't be able to create IP types with the DLR in 2.0. I was hoping that that would be a feature. By the way, do you guys have an idea of when 2.0 final will be released? Or at least an idea of what stages it has left to go through (how many more alpha stages, beta releases, RC's)? I couldn't find this on CodePlex. Thanks, Rocco ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dino Viehland Sent: Wednesday, February 06, 2008 3:54 PM To: Discussion of IronPython Subject: Re: [IronPython] Exporting Python code as an assembly The extra __'s are expected. When we enabled this in 1.1.1 we didn't want to significantly alter the experience between 1.1 and 1.1.1. The problem with 1.1 was that if the caller passed in an attribute to filter by (DataGridView passes in BrowsableAttribute) we would say "attributes? We don't have attributes, so you'll get an empty collection". In 1.1.1 we'll return just about anything if browsable is set. In 2.0, where we have a little more leeway to change things, we're more aggressive about filtering out things you probably don't want to see. You can always not auto-generate the columns and you'll get the columns you presumably want. The AllowNew is going to be an unfortunate limitation - Python type instances can't (easily) be created by anyone except for the Python runtime. The reason is we need to pass a PythonType object into the contructor so the object knows it's type in the Python world. So we probably can't do much about this one :(. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Pigneri, Rocco Sent: Wednesday, February 06, 2008 12:47 PM To: Discussion of IronPython Subject: Re: [IronPython] Exporting Python code as an assembly Dino, Ah ha! Well, it didn't work under 1.1, but under 1.1.1, it worked nearly right out of the box. When I used a static interface under 1.1, I only got the static properties in the DataGridView. However, under 1.1.1, I am getting a whole extra slew of information in my Grids (__weakref__, __doc__, the hidden values, the properties themselves, every function in the type) when I turn on AutoColumnGenerate. Is this what I should be expecting? Also, it seems that if I turn on user creation of new elements (BindingList.AllowNew = True), then the component crashes with an error stating that it cannot find the constructor for my type, whether or not I have defined it. Is this also to be expected or not? Thank you, Rocco Pigneri ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dino Viehland Sent: Tuesday, February 05, 2008 4:55 PM To: Discussion of IronPython Subject: Re: [IronPython] Exporting Python code as an assembly Data binding isn't working for you? We have support for this via CustomTypeDescriptors which describe the Python objects and we have some test cases to verify it works. Note it was broken before 1.1.1 although it's been working in 2.0 for a little while now. For example: import clr clr.AddReference('System.Windows.Forms') import System.Windows.Forms as SWF import System class AgeQualifier(object): def __get__(self, instance, ctx): if instance.Age < 13: return 'young' if instance.Age < 20: return 'teen' if instance.Age < 30: return 'twenties' if instance.Age < 40: return 'thirties' if instance.Age < 50: return 'forties' return 'old' SAMPLE_DATA = [('Joe', 23, 'twenties'), ('Bob', 8, 'young'), ('Thomas', 32, 'thirties'), ('Patrick', 41, 'forties'), ('Kathy', 19, 'teen'), ('Sue' , 77, 'old'),] class Person(System.Object): def __init__(self, name, age): self._name = name self._age = age def get_name(self): return self._name def set_name(self, value): self._name = value Name = property(get_name, set_name) def get_age(self): return self._age def set_age(self, value): self._age = value Age = property(get_age, set_age) AgeDescription = AgeQualifier() class Form(SWF.Form): def __init__(self): SWF.Form.__init__(self) self._people = people = [] for name, age, ignored in SAMPLE_DATA: people.append(Person(name, age)) grid = SWF.DataGridView() grid.AutoGenerateColumns = True grid.DataSource = people grid.Dock = SWF.DockStyle.Fill self.grid = grid self.Controls.Add(grid) form = Form() SWF.Application.Run(form) From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Pigneri, Rocco Sent: Tuesday, February 05, 2008 9:15 AM To: Discussion of IronPython Subject: Re: [IronPython] Exporting Python code as an assembly Curt, This is a great feature and was one of the first features that I investigated when I first got my hands on IP. I see an immediate need for this feature in using data binding with Windows Forms controls. Many controls (such as DataGridView and ListView) reflect over the properties of bound objects in order to display this data dynamically with no programmer setup. Because IP types are dynamic, WinForms cannot find any properties to bind and creates an "empty" object. In order to use these features now, I must create static interfaces with the required properties in a separate assembly and then inherit that interface whenever I bind to business objects. To make using these UI controls easier, it would be great if property statements could be turned into static properties either automatically or via a flag. It seems that IP already matches properties to the correct static getter/setter as defined in the interfaces so this should be a reasonable request. This staticization would remove the need for the separate static interface. Another situation in which this would be really helpful--although less critical--involves situations where I want to use a static tool on an IP assembly (for example, I want to use NUnit to test my IP classes). I say that this is not critical as a lot of tools already have Python-specific versions available--PyUnit is a good example. Finally, would there be a way to simplify programmer work by providing "standard" static creators that are turned on and off at a high level? For example, programmers could use a "compiler" switch to turn all functions into "void func(object, . . .)" and "object func(obj. . . )". I see this being useful in situations such as using NUnit because all that is really needed is the proper number of arguments and the right function name (all of which are already known in Python). If things then work the way that I think they work, you could then just pass the objects into the correct comparators, and if they are the right type, then the tests will run. Otherwise, you'll get an exception. Hope that helps, Rocco ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Monday, February 04, 2008 1:31 PM To: Discussion of IronPython Subject: [IronPython] Exporting Python code as an assembly After a bit of spare-time hacking this weekend, I've got a "proof-of-concept" program that takes a Python class and exports it as a (statically-defined) assembly. It uses Pythonic function annotations to signal attributes and input and output types to the wrapper generator. You end up with something like this def Test(object): @ClrAttribute(Xunit.FactAttribute) def WorthlessTest(self): Xunit.Assert.Equal[type(1)](1, 1) @ClrAccepts(System.String, System.Int32) @ClrReturns(System.Int32) def CalculateValue(self, s, i): return len(s) + i The program takes this source and spits out a DLL containing the class "Test" which implements "WorthlessTest" and "CalculateValue". The class itself contains a reference to the actual Python object, and each of the public functions simply delegates to the Pythonic implementation. I'm still working on cleaning up the source a little before releasing it, but was wondering if anyone had some feedback on the design as described so far. What should be changed or implemented in order for this to be more useful to you? Thanks, -Curt -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at voidspace.org.uk Thu Feb 7 21:24:07 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Thu, 07 Feb 2008 20:24:07 +0000 Subject: [IronPython] Decorators on classes In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF47C8F4F@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <47A7603D.8040102@voidspace.org.uk> <47A76D2D.2040500@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB15@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A78B78.4070903@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227010FC893CB44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47A797BD.7010906@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF47C8F4F@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <47AB68E7.20606@voidspace.org.uk> Dino Viehland wrote: > This might be something fun to look at during the sprints at PyCon. > I will definitely be staying for the sprints - either as part of a Resolver sprint or under my own steam... Michael > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord > Sent: Monday, February 04, 2008 2:55 PM > To: Discussion of IronPython > Subject: Re: [IronPython] Decorators on classes > > Hello Dino, > > That sounds *great*, and is something really needed by IronPython. How > long do you think it will take you to implement? <0.5 wink> > > Michael > http://www.manning.com/foord > > Dino Viehland wrote: > >> Ok, maybe it's a little optimistic or maybe it needs a couple of hooks exposed, but it's not too crazy. >> >> As other people have pointed out decorators are a runtime concept and I don't think we get to change that. So consider a class decorator such as: >> >> def ClrAttribute(attr): >> def attrFunc(class): >> # do something smart here with attr >> return attrFunc >> >> @ClrAttribute(System.SerializableAttribute) >> class X(ISomething, object): >> @ClrAttribute(SomeOtherAttribte) >> def DoSomething(self): >> return 42 >> >> >> As Curt mentioned we do a bunch of caching and such with NewTypeMaker and maybe spit out a new type. That's all going to happen before the decorator gets to run - but we'll only create a new type once so there isn't too much overhead here :). >> >> >From there you could copy that type w/ Reflection.Emit but add the attribute(s) on it, and then create a new instance of it passing in the PythonType object to its constructor (that's how Python types work - the instance holds onto a copy of the PythonType, the one problem here being that the UnderlyingSystemType of the PythonType would now be wrong, so that might need a hook). This could also include applying the attributes to methods and potentially manifesting concretely typed methods. This same sort of approach might even work w/ a meta-class. >> >> Plugging into NewTypeMaker would simplify this but I don't think makes it impossible. >> >> There's also other potential problems with systems based up types and attributes: Sometimes they want a type that lives in an assembly and sometimes they want to create instances of types (and they don't know to pass in a PythonType object to the constructor). >> >> -----Original Message----- >> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord >> Sent: Monday, February 04, 2008 2:03 PM >> To: Discussion of IronPython >> Subject: Re: [IronPython] Decorators on classes >> >> Dino Viehland wrote: >> >> >>> FYI IP 2.0 is tracking 2.5 and we have the big pieces in place plus many small pieces (although there's more to go). In 1.1 we had -X:Python25 which enabled selective 2.5 features and we could conceptually do the same sort of thing for 2.0 so that it includes one or two 2.6 features such as class decorators. >>> >>> >From there the decorators to support attributes could even be written in Python. >>> >>> >>> >>> >> Is that right - could attributes be added to an IronPython class (or >> instances) at runtime using reflection? Earlier parts of this >> conversation implied that this wasn't the case... >> >> Decorators are only syntactic sugar, so the lack of class decorators >> isn't an impediment... >> >> Michael >> >> >> >> >>> -----Original Message----- >>> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Keith J. Farmer >>> Sent: Monday, February 04, 2008 1:40 PM >>> To: Discussion of IronPython; Discussion of IronPython >>> Subject: Re: [IronPython] Decorators on classes >>> >>> Grandfathering: Giving more consideration to retaining compatibility than it deserves. :) >>> >>> Obviously, IronPython should prioritize compatibility with Py2.4, but for obvious reasons I limit that to seeing IP as a consumer of CPy, not the other way around. On the other hand, IP must also be able to consume .NET, and .NET is increasingly making use of things the IP cannot yet express. (I thought of another framework that attributes are used on -- WCF. There are also XML serialization attributes.) >>> >>> To that end, I think it would be worthwhile, for the purpose of .NET attributes, to have decorators or their analogues available to IronPython in the current stage of development. That is, I think it should be that IronPython = CPy 2.4 + .NET Attributes + other .NET-isms expressed in a Pythonic way. >>> >>> ________________________________ >>> >>> From: users-bounces at lists.ironpython.com on behalf of Michael Foord >>> Sent: Mon 2/4/2008 11:53 AM >>> To: Discussion of IronPython >>> Subject: Re: [IronPython] Decorators on classes >>> >>> >>> >>> Keith J. Farmer wrote: >>> >>> >>> >>>> I've had no problems with not grandfathering in older APIs, and am quite happy to not grandfather in older syntax, either. >>>> >>>> >>>> >>>> >>> What do you mean by 'grandfathering' in this context? >>> >>> Michael >>> >>> >>> >>> >>>> I agree that IronPython would have to be able to distinguish between CLR attributes and Python decorators, inasmuch as CLR attributes are a static part of the class/member definition. But I don't think it's an insurmountable problem, and solving it in the DLR, actually, would be very useful. >>>> >>>> I wouldn't expect that class authors would want to change the set of .NET attributes frequently if at all -- it doesn't match how they've been designed and how they've evolved, so creating the attributed base class once (and then having pythonic decorators coming in and out at will) seems like a reasonable approach to me. >>>> >>>> ________________________________ >>>> >>>> From: users-bounces at lists.ironpython.com on behalf of Curt Hagenlocher >>>> Sent: Mon 2/4/2008 11:13 AM >>>> To: Discussion of IronPython >>>> Subject: Re: [IronPython] Decorators on classes >>>> >>>> >>>> Oh! I didn't realize that about 2.6. >>>> >>>> There is indeed a big difference between a Python runtime decorator and a .NET compile time attribute; in fact, the similarities are superficial at best. >>>> >>>> .NET attributes are totally static, so there's no way to modify a .NET class definition to add them. The IronPython engine would have to recognize particular class-level Pythonic annotations and use that information to emit a new CLR class to represent the Python class. It already emits CLR classes as needed to represent Python classes. By "as needed", I mean that a specific CLR base class plus a specific set of CLR interfaces will uniquely determine a class to be emitted by IronPython. This class is cached so that -- once generated -- any new Python class definition that matches this set of (CLR base class plus interfaces) will reuse the same CLR class definition. >>>> >>>> What you'd have to change is to put the class-level attributes onto the generated CLR class, then change caching so that the key is (CLR base class plus interfaces plus attributes). It's definitely doable, but raises intriguing questions about "purity". And you'd also need to consider the impact on the larger DLR. >>>> >>>> Method-level attributes are an entirely different matter. >>>> >>>> On Feb 4, 2008 10:58 AM, Michael Foord wrote: >>>> >>>> >>>> Class decorators will be in Python 2.6 - but there is a big difference >>>> between a Python runtime decorator and .NET compile time attributes. Is >>>> it possible to attach attributes at runtime using the reflection API? >>>> >>>> Michael >>>> http://www.manning.com/foord >>>> >>>> >>>> Keith J. Farmer wrote: >>>> > Can I resurrect this forgotten soul? http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=13583 >>>> > >>>> > Having just finished working on LINQ to SQL, I'm convinced that future LINQ providers will be making heavy use of .NET attributes not just on properties, but on classes themselves. Being able to express these attributes in IronPython is a tremendous bonus. That there be one and only one way to express these is paramount. >>>> > >>>> > _______________________________________________ >>>> > Users mailing list >>>> > Users at lists.ironpython.com >>>> > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>>> > >>>> > >>>> >>>> _______________________________________________ >>>> Users mailing list >>>> Users at lists.ironpython.com >>>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>>> >>>> >>>> >>>> _______________________________________________ >>>> Users mailing list >>>> Users at lists.ironpython.com >>>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>>> >>>> >>>> >>>> >>>> >>> _______________________________________________ >>> Users mailing list >>> Users at lists.ironpython.com >>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> >>> >>> _______________________________________________ >>> Users mailing list >>> Users at lists.ironpython.com >>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> _______________________________________________ >>> Users mailing list >>> Users at lists.ironpython.com >>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> >>> >>> >>> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > From fuzzyman at voidspace.org.uk Thu Feb 7 23:46:33 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Thu, 07 Feb 2008 22:46:33 +0000 Subject: [IronPython] HybridMapping is full Error In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF47C95C0@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <47AAE43B.1050608@resolversystems.com> <7AD436E4270DD54A94238001769C2227011CF47C95C0@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <47AB8A49.7090205@voidspace.org.uk> Dino Viehland wrote: > It looks like there's an internal limit that prevents us from ever having more than 4096 PythonFile objects in existance. Is it possible that you have that many file objects in existence that aren't getting freed? Also just closing them won't be enough, they actually have to get collected by the GC. > > I don't think anything has actually changed here between 1.1 and 1.1.1 so it might just be hitting slightly different lifetimes. But this limit does seem pretty stupid (and it's still in 2.0 as well apparently :( ). > Ok - but although 4096 sounds like a low *general* limit it should be fine for us. We certainly always close our file handles - I wonder why they wouldn't be garbage collected? Hmmm.... One of our devs did a great blog entry recently on tracing resource leaks in IronPython applications: http://blog.kamil.dworakowski.name/2008/02/debugging-memory-problems-in-ironpython.html Michael Foord Michael > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord > Sent: Thursday, February 07, 2008 2:58 AM > To: Discussion of IronPython > Subject: [IronPython] HybridMapping is full Error > > Hello, > > After upgrading to IronPython 1.1.1 we are seeing (sporadically) the > following exception when we run our full test suite. > > Any idea what the cause(s) could be? > > Unexpected SystemException running tests: System.SystemException: > HybridMapping is full > > at IronPython.Runtime.HybridMapping`1.WeakAdd(T value) > > at IronPython.Runtime.PythonFile..ctor(Stream stream, Encoding > encoding, String mode, Boolean weakMapping) > > at IronPython.Runtime.PythonFile.Make(ICallerContext context, > DynamicType cls, String name, String mode, Int32 bufsize) > > at IronPython.Runtime.PythonFile.Make(ICallerContext context, > DynamicType cls, String name, String mode) > > at Make##3549(ICallerContext , Object , Object , Object ) > > at > IronPython.Runtime.Calls.FastCallableWithContext3.Call(ICallerContext > context, Object arg0, Object arg1, Object arg2) > > at > IronPython.Runtime.Calls.FastCallableWithContext3.Call(ICallerContext > context, Object[] args) > > at > IronPython.Compiler.MethodBinder.MethodTarget.Call(ICallerContext > context, Object[] args) > > at IronPython.Compiler.MethodBinder.TargetSet.Call(ICallerContext > context, CallType callType, Object[] args) > > at > IronPython.Compiler.MethodBinder.TargetSet.Call3(ICallerContext context, > Object arg0, Object arg1, Object arg2) > > at > IronPython.Runtime.Calls.FastCallableWithContextAny.Call(ICallerContext > context, Object arg0, Object arg1, Object arg2) > > at > IronPython.Runtime.Calls.FastCallableWithContextAny.Call(ICallerContext > context, Object[] args) > > at IronPython.Runtime.Calls.BuiltinFunction.Call(ICallerContext > context, Object[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object[] args) > > at > IronPython.Runtime.Types.DynamicType.CreateInstance(ICallerContext con > text, Object[] args, String[] names) > > at IronPython.Runtime.Types.DynamicType.Call(ICallerContext > context, Obje > ct[] args, String[] names) > > at IronPython.Runtime.Types.DynamicType.Call(ICallerContext > context, Obje > ct[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1) > > at linecache.updatecache$f105(Object filename) in > C:\Dev\buildshare\Resol > ver-df367\python24\linecache.py:line 105 > > at IronPython.Runtime.Calls.Function1.Call(ICallerContext > context, Object > arg0) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0) > > at linecache.getlines$f103(Object filename) in > C:\Dev\buildshare\Resolver > -df367\python24\linecache.py:line 40 > > at IronPython.Runtime.Calls.Function1.Call(ICallerContext > context, Object > arg0) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0) > > at linecache.getline$f101(Object filename, Object lineno) in > C:\Dev\build > share\Resolver-df367\python24\linecache.py:line 14 > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > arg0, Object arg1) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1) > > at traceback.extract_tb$f89(Object tb, Object limit) in > C:\Dev\buildshare > \Resolver-df367\python24\traceback.py:line 101 > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > arg0, Object arg1) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1) > > at traceback.format_tb$f88(Object tb, Object limit) in > C:\Dev\buildshare\ > Resolver-df367\python24\traceback.py:line 76 > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > arg0, Object arg1) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1) > > at traceback.format_exception$f91(Object etype, Object value, > Object tb, > Object limit) in > C:\Dev\buildshare\Resolver-df367\python24\traceback.py:line 142 > > > at IronPython.Runtime.Calls.Function4.Call(ICallerContext > context, Object > arg0, Object arg1, Object arg2) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1, Object arg2) > > at > unittest._exc_info_to_string$f13(FunctionEnvironment16Dictionary $env, > Object self, Object err, Object test) in > C:\Dev\buildshare\Resolver-df367\pytho > n24\unittest.py:line 153 > > at IronPython.Runtime.Calls.Function3.Call(ICallerContext > context, Object > arg0, Object arg1, Object arg2) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object arg0, Object arg1, Object arg2) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object ar > g0, Object arg1) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1) > > at unittest.addError$f8(FunctionEnvironment16Dictionary $env, > Object self > , Object test, Object err) in > C:\Dev\buildshare\Resolver-df367\python24\unittest > .py:line 124 > > at IronPython.Runtime.Calls.Function3.Call(ICallerContext > context, Object > arg0, Object arg1, Object arg2) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object ar > g0, Object arg1, Object arg2) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1, Object arg2) > > at unittest.addError$f72(FunctionEnvironment16Dictionary $env, > Object sel > f, Object test, Object err) in > C:\Dev\buildshare\Resolver-df367\python24\unittes > t.py:line 656 > > at IronPython.Runtime.Calls.Function3.Call(ICallerContext > context, Object > arg0, Object arg1, Object arg2) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object ar > g0, Object arg1, Object arg2) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1, Object arg2) > > at > TestUtils.PublishingTestRunner.addError$f2861(FunctionEnvironment16Dic > tionary $env, Object self, Object test, Object err) in > C:\Dev\buildshare\Resolve > r-df367\TestUtils\PublishingTestRunner.py:line 40 > > at IronPython.Runtime.Calls.Function3.Call(ICallerContext > context, Object > arg0, Object arg1, Object arg2) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object arg0, Object arg1, Object arg2) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object ar > g0, Object arg1) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1) > > at unittest.run$f26(FunctionEnvironmentNDictionary $env, Object > self, Obj > ect result) in > C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 255 > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > arg0, Object arg1) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object ar > g0, Object arg1) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1) > > at TestUtils.TestCase.run$f252(FunctionEnvironment32Dictionary > $env, Obje > ct self, Object result) in > C:\Dev\buildshare\Resolver-df367\TestUtils\TestCase.p > y:line 139 > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > arg0, Object arg1) > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > [] args) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object instance, Object[] args) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object[] > args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndCo > ntext(ICallerContext context, Object func, Object[] args, String[] > names, Object > argsTuple, Object kwDict) > > at unittest.__call__$f27(FunctionEnvironmentNDictionary $env, > Object self > , Object args, Object kwds) in > C:\Dev\buildshare\Resolver-df367\python24\unittes > t.py:line 281 > > at unittest.__call__$f27(FunctionEnvironmentNDictionary , Object[] ) > > at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext > context, Object > [] args) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object instance, Object[] args) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object[] > args) > > at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) > > at > IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar > get, SymbolId name, Object& ret, Object[] args) > > at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object > func, Objec > t[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0) > > at unittest.run$f44(FunctionEnvironment16Dictionary $env, Object > self, Ob > ject result) in > C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 429 > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > arg0, Object arg1) > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > [] args) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object instance, Object[] args) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object[] > args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndCo > ntext(ICallerContext context, Object func, Object[] args, String[] > names, Object > argsTuple, Object kwDict) > > at unittest.__call__$f45(FunctionEnvironment16Dictionary $env, > Object sel > f, Object args, Object kwds) in > C:\Dev\buildshare\Resolver-df367\python24\unitte > st.py:line 433 > > at unittest.__call__$f45(FunctionEnvironment16Dictionary , Object[] ) > > at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext > context, Object > [] args) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object instance, Object[] args) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object[] > args) > > at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) > > at > IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar > get, SymbolId name, Object& ret, Object[] args) > > at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object > func, Objec > t[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0) > > at unittest.run$f44(FunctionEnvironment16Dictionary $env, Object > self, Ob > ject result) in > C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 429 > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > arg0, Object arg1) > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > [] args) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object instance, Object[] args) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object[] > args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndCo > ntext(ICallerContext context, Object func, Object[] args, String[] > names, Object > argsTuple, Object kwDict) > > at unittest.__call__$f45(FunctionEnvironment16Dictionary $env, > Object sel > f, Object args, Object kwds) in > C:\Dev\buildshare\Resolver-df367\python24\unitte > st.py:line 433 > > at unittest.__call__$f45(FunctionEnvironment16Dictionary , Object[] ) > > at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext > context, Object > [] args) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object instance, Object[] args) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object[] > args) > > at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) > > at > IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar > get, SymbolId name, Object& ret, Object[] args) > > at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object > func, Objec > t[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0) > > at unittest.run$f78(FunctionEnvironment8Dictionary $env, Object > self, Obj > ect test) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 701 > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > arg0, Object arg1) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object arg0, Object arg1) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object ar > g0) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0) > > at TestUtils.RunTest.RunTest$f1(Object testClass, Object > saveResults, Obj > ect runs, Object schedule) in > C:\Dev\buildshare\Resolver-df367\TestUtils\RunTest > .py:line 28 > at IronPython.Runtime.HybridMapping`1.WeakAdd(T value) > > at IronPython.Runtime.PythonFile..ctor(Stream stream, Encoding > encoding, > String mode, Boolean weakMapping) > > at IronPython.Runtime.PythonFile.Make(ICallerContext context, > DynamicType > cls, String name, String mode, Int32 bufsize) > > at IronPython.Runtime.PythonFile.Make(ICallerContext context, > DynamicType > cls, String name, String mode) > > at Make##3549(ICallerContext , Object , Object , Object ) > > at > IronPython.Runtime.Calls.FastCallableWithContext3.Call(ICallerContext > context, Object arg0, Object arg1, Object arg2) > > at > IronPython.Runtime.Calls.FastCallableWithContext3.Call(ICallerContext > context, Object[] args) > > at > IronPython.Compiler.MethodBinder.MethodTarget.Call(ICallerContext cont > ext, Object[] args) > > at IronPython.Compiler.MethodBinder.TargetSet.Call(ICallerContext > context > , CallType callType, Object[] args) > > at > IronPython.Compiler.MethodBinder.TargetSet.Call3(ICallerContext contex > t, Object arg0, Object arg1, Object arg2) > > at > IronPython.Runtime.Calls.FastCallableWithContextAny.Call(ICallerContex > t context, Object arg0, Object arg1, Object arg2) > > at > IronPython.Runtime.Calls.FastCallableWithContextAny.Call(ICallerContex > t context, Object[] args) > > at IronPython.Runtime.Calls.BuiltinFunction.Call(ICallerContext > context, > Object[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object[] args) > > at > IronPython.Runtime.Types.DynamicType.CreateInstance(ICallerContext con > text, Object[] args, String[] names) > > at IronPython.Runtime.Types.DynamicType.Call(ICallerContext > context, Obje > ct[] args, String[] names) > > at IronPython.Runtime.Types.DynamicType.Call(ICallerContext > context, Obje > ct[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1) > > at linecache.updatecache$f105(Object filename) in > C:\Dev\buildshare\Resol > ver-df367\python24\linecache.py:line 105 > > at IronPython.Runtime.Calls.Function1.Call(ICallerContext > context, Object > arg0) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0) > > at linecache.getlines$f103(Object filename) in > C:\Dev\buildshare\Resolver > -df367\python24\linecache.py:line 40 > > at IronPython.Runtime.Calls.Function1.Call(ICallerContext > context, Object > arg0) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0) > > at linecache.getline$f101(Object filename, Object lineno) in > C:\Dev\build > share\Resolver-df367\python24\linecache.py:line 14 > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > arg0, Object arg1) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1) > > at traceback.extract_tb$f89(Object tb, Object limit) in > C:\Dev\buildshare > \Resolver-df367\python24\traceback.py:line 101 > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > arg0, Object arg1) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1) > > at traceback.format_tb$f88(Object tb, Object limit) in > C:\Dev\buildshare\ > Resolver-df367\python24\traceback.py:line 76 > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > arg0, Object arg1) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1) > > at traceback.format_exception$f91(Object etype, Object value, > Object tb, > Object limit) in > C:\Dev\buildshare\Resolver-df367\python24\traceback.py:line 142 > > > at IronPython.Runtime.Calls.Function4.Call(ICallerContext > context, Object > arg0, Object arg1, Object arg2) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1, Object arg2) > > at > unittest._exc_info_to_string$f13(FunctionEnvironment16Dictionary $env, > Object self, Object err, Object test) in > C:\Dev\buildshare\Resolver-df367\pytho > n24\unittest.py:line 153 > > at IronPython.Runtime.Calls.Function3.Call(ICallerContext > context, Object > arg0, Object arg1, Object arg2) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object arg0, Object arg1, Object arg2) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object ar > g0, Object arg1) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1) > > at unittest.addError$f8(FunctionEnvironment16Dictionary $env, > Object self > , Object test, Object err) in > C:\Dev\buildshare\Resolver-df367\python24\unittest > .py:line 124 > > at IronPython.Runtime.Calls.Function3.Call(ICallerContext > context, Object > arg0, Object arg1, Object arg2) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object ar > g0, Object arg1, Object arg2) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1, Object arg2) > > at unittest.addError$f72(FunctionEnvironment16Dictionary $env, > Object sel > f, Object test, Object err) in > C:\Dev\buildshare\Resolver-df367\python24\unittes > t.py:line 656 > > at IronPython.Runtime.Calls.Function3.Call(ICallerContext > context, Object > arg0, Object arg1, Object arg2) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object ar > g0, Object arg1, Object arg2) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1, Object arg2) > > at > TestUtils.PublishingTestRunner.addError$f2861(FunctionEnvironment16Dic > tionary $env, Object self, Object test, Object err) in > C:\Dev\buildshare\Resolve > r-df367\TestUtils\PublishingTestRunner.py:line 40 > > at IronPython.Runtime.Calls.Function3.Call(ICallerContext > context, Object > arg0, Object arg1, Object arg2) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object arg0, Object arg1, Object arg2) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object ar > g0, Object arg1) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1) > > at unittest.run$f26(FunctionEnvironmentNDictionary $env, Object > self, Obj > ect result) in > C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 255 > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > arg0, Object arg1) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object ar > g0, Object arg1) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0, Object arg1) > > at TestUtils.TestCase.run$f252(FunctionEnvironment32Dictionary > $env, Object self, Object result) in > C:\Dev\buildshare\Resolver-df367\TestUtils\TestCase.py:line 139 > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > arg0, Object arg1) > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > [] args) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object instance, Object[] args) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object[] > args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndContext(ICallerContext > context, Object func, Object[] args, String[] names, Object > argsTuple, Object kwDict) > > at unittest.__call__$f27(FunctionEnvironmentNDictionary $env, > Object self > , Object args, Object kwds) in > C:\Dev\buildshare\Resolver-df367\python24\unittes > t.py:line 281 > > at unittest.__call__$f27(FunctionEnvironmentNDictionary , Object[] ) > > at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext > context, Object > [] args) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object instance, Object[] args) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object[] > args) > > at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) > > at > IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar > get, SymbolId name, Object& ret, Object[] args) > > at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object > func, Objec > t[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0) > > at unittest.run$f44(FunctionEnvironment16Dictionary $env, Object > self, Ob > ject result) in > C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 429 > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > arg0, Object arg1) > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > [] args) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object instance, Object[] args) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object[] > args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndCo > ntext(ICallerContext context, Object func, Object[] args, String[] > names, Object > argsTuple, Object kwDict) > > at unittest.__call__$f45(FunctionEnvironment16Dictionary $env, > Object sel > f, Object args, Object kwds) in > C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 433 > > at unittest.__call__$f45(FunctionEnvironment16Dictionary , Object[] ) > > at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext > context, Object > [] args) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object instance, Object[] args) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object[] > args) > > at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) > > at > IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar > get, SymbolId name, Object& ret, Object[] args) > > at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object > func, Objec > t[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0) > > at unittest.run$f44(FunctionEnvironment16Dictionary $env, Object > self, Ob > ject result) in > C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 429 > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > arg0, Object arg1) > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > [] args) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object instance, Object[] args) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object[] > args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithArgsTupleAndKeywordDictAndCo > ntext(ICallerContext context, Object func, Object[] args, String[] > names, Object > argsTuple, Object kwDict) > > at unittest.__call__$f45(FunctionEnvironment16Dictionary $env, > Object self, Object args, Object kwds) in > C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 433 > > at unittest.__call__$f45(FunctionEnvironment16Dictionary , Object[] ) > > at IronPython.Runtime.Calls.FunctionX.Call(ICallerContext > context, Object > [] args) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext co > ntext, Object instance, Object[] args) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object[] > args) > > at IronPython.Runtime.Operations.Ops.Call(Object func, Object[] args) > > at > IronPython.Runtime.Types.DynamicType.TryInvokeSpecialMethod(Object tar > get, SymbolId name, Object& ret, Object[] args) > > at IronPython.Runtime.Types.DynamicType.CallOnInstance(Object > func, Objec > t[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object[] args) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext conte > xt, Object func, Object arg0) > > at unittest.run$f78(FunctionEnvironment8Dictionary $env, Object > self, Obj > ect test) in C:\Dev\buildshare\Resolver-df367\python24\unittest.py:line 701 > > at IronPython.Runtime.Calls.Function2.Call(ICallerContext > context, Object > arg0, Object arg1) > > at > IronPython.Runtime.Calls.PythonFunction.CallInstance(ICallerContext > context, Object arg0, Object arg1) > > at IronPython.Runtime.Calls.Method.Call(ICallerContext context, > Object arg0) > > at > IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext > context, Object func, Object arg0) > > at TestUtils.RunTest.RunTest$f1(Object testClass, Object > saveResults, Obj > ect runs, Object schedule) in > C:\Dev\buildshare\Resolver-df367\TestUtils\RunTest.py:line 28 > > > > > > > -- > Michael Foord > Senior Software Engineer, Resolver Systems Ltd. > michael.foord at resolversystems.com > +44 (0) 20 7253 6372 > > We're hiring! http://www.resolversystems.com/jobs/ > 17a Clerkenwell Road, London EC1M 5RD, UK > VAT No.: GB 893 5643 79 Registered in England and Wales as company number 5467329. > Registered address: 843 Finchley Road, London NW11 8NA, UK > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > From curt at hagenlocher.org Sat Feb 9 18:17:11 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Sat, 9 Feb 2008 09:17:11 -0800 Subject: [IronPython] PythonType.CreateInstance not calling __init__ Message-ID: The following code creates a Python class "foo" with a single method __init__. It then gets the class object. string code = "class foo(object):\n\tdef __init__(self):\n\t\tprint 'hello world'\n"; SourceUnit scriptSource = PythonEngine.CurrentEngine.CreateScriptSourceFromString(code, SourceCodeKind.File); IScriptScope scope = PythonEngine.CurrentEngine.CreateScope(); PythonEngine.CurrentEngine.Execute(scope, scriptSource); object obj2; scope.TryGetVariable("foo", out obj2); PythonType theClass = obj2 as PythonType; I then use PythonType.CreateInstance to create the object. LanguageContext language = LanguageContext.FromEngine( PythonEngine.CurrentEngine); Scope scope2 = new Scope(language); CodeContext context = new CodeContext(scope2, language); object foo = theClass.CreateInstance(context, new object[0]); At this point "foo" contains an object with the Python type "foo". However, the __init__ method was never called. What am I doing wrong? -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From curt at hagenlocher.org Sat Feb 9 22:13:19 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Sat, 9 Feb 2008 13:13:19 -0800 Subject: [IronPython] PythonType.CreateInstance not calling __init__ In-Reply-To: References: Message-ID: A little more poking suggests that CreateInstance._ctor is really the equivalent of __new__ and not __init__. I changed the code to say PythonTypeOps.TypeCaller ctor = new PythonTypeOps.TypeCaller(theClass); object foo = ctor.Call(context); and all is now well with the world. On Feb 9, 2008 9:17 AM, Curt Hagenlocher wrote: > The following code creates a Python class "foo" with a single method > __init__. It then gets the class object. > > string code = "class foo(object):\n\tdef __init__(self):\n\t\tprint > 'hello world'\n"; > SourceUnit scriptSource = > PythonEngine.CurrentEngine.CreateScriptSourceFromString(code, > SourceCodeKind.File); > IScriptScope scope = PythonEngine.CurrentEngine.CreateScope(); > PythonEngine.CurrentEngine.Execute(scope, scriptSource); > object obj2; > scope.TryGetVariable("foo", out obj2); > PythonType theClass = obj2 as PythonType; > > I then use PythonType.CreateInstance to create the object. > > LanguageContext language = LanguageContext.FromEngine( > PythonEngine.CurrentEngine); > Scope scope2 = new Scope(language); > CodeContext context = new CodeContext(scope2, language); > object foo = theClass.CreateInstance(context, new object[0]); > At this point "foo" contains an object with the Python type "foo". > However, the __init__ method was never called. > > What am I doing wrong? > > -- > Curt Hagenlocher > curt at hagenlocher.org > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sraju at zeomega.com Mon Feb 11 09:06:07 2008 From: sraju at zeomega.com (Raju Sivalingam) Date: Mon, 11 Feb 2008 13:36:07 +0530 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: References: <47A75FA4.5090308@voidspace.org.uk> <47A76257.6090307@voidspace.org.uk> <47A79A3A.8070002@voidspace.org.uk> <47A869B5.8040505@resolversystems.com> <47A8A6E3.1050200@resolversystems.com> Message-ID: <47B001EF.7070207@zeomega.com> Hi When i run MakeModule, i am getting this error "AttributeError: 'NoneType' object has no attribute 'GetGetMethod' ". For testing just i was running this command. *.\ipy.exe MakeModule.py Xtest.py -Thanks Raju*** Curt Hagenlocher wrote: > You can download my work-in-progress from > http://hagenlocher.org/software/ClrWrapper.zip > > The source consists of the three files ClrBuilder.py, ClrWrapper.py > and MakeModule.py. There are also two "demo" files: Xtest.py and > WcfServer.py. The program can currently be run as follows: > > PS F:\IronPython-2.0A8> *.\ipy.exe MakeModule.py Xtest.py* > > This will produce a file called Xtest.dll. > > At this point, the application doesn't require any of the standard > Python library files. It's only been tried with the Alpha 8 binaries > -- and in fact, the hosting interfaces for IronPython still aren't > entirely stable so there's no guarantee that the DLLs produced will > work with Alpha 9. > > Xtest.py is a trivial application that implements a single > xunit-compatible unit test > PS F:\IronPython-2.0A8> *.\xunit.console.exe Xtest.dll /noshadow* > . > Total tests: 1, Failures: 0, Skipped: 0, Time: 0.275 seconds > WcfServer.py theoretically implements a WCF server, though I haven't > gotten as far as actually testing the output yet. (The generated > code passes the eyeball compiler.) > > Code quality is unimpressive; your mileage may vary. And I've got to > get back to my "day job" for a few hours now :). > > -- > Curt Hagenlocher > curt at hagenlocher.org > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From praveen at mahiti.org Tue Feb 12 06:31:09 2008 From: praveen at mahiti.org (Praveen Kumar) Date: Tue, 12 Feb 2008 11:01:09 +0530 Subject: [IronPython] Please help me out its very urgent Message-ID: <6f7fd6e90802112131n3e74bdbblc1f18a0b82f9e2d7@mail.gmail.com> I am new for Ironpython for ASP.net, earlier i was using only Visual studio 2005 and struggling with to read excel file without M$ Excel object, bt i could nt get any other object which could read excel sheet. But suddenly i got one Lingfo ? Python "xlrd" package for extracting data from Excel files ? 0.6.1final which can read successfully excel sheet as i desired.but the problem is i dont knw hw can i use with IronPython Asp.net(Microsoft IronPython for ASP.NET). i have seperately installed Python2.4.. i tried with python2.4 its working failrly.while installing xlrd it automatically search D:\Python24\, there were no option to configure it nad installed in D:\Python24\Lib\site-packages\. Then i copy the XLRD package and paste C:\Program Files\Microsoft IronPython for ASP.NET\Lib\site-packages\ and wrote the python script ExcelModule.py class readexcel(object): def __init__(self,filename): """ Returns a readexcel object of the specified filename - this may take a little while because the file must be parsed into memory """ import sys sys.path.append('D:\Python24\Lib') sys.path.append('D:\Python24\Lib\site-packages') from xlrd import * print dir(xlrd) return printed import os.path if not os.path.isfile(filename): raise NameError, "%s is not a valid filename" % filename self.__filename__ = filename self.__book__ = xlrd.open_workbook(filename) self.__sheets__ = {} self.__sheetnames__ = [] for i in self.__book__.sheet_names(): uniquevars = [] firstrow = 0 sheet = self.__book__.sheet_by_name(i) for row in range(sheet.nrows): types,values = sheet.row_types(row),sheet.row_values(row) nonblank = False for j in values: if j != '': nonblank=True break if nonblank: # Generate a listing of Unique Variable Names for Use as # Dictionary Keys In Extraction. Duplicate Names will # be replaced with "F#" variables = self.__formatrow__(types,values,False) unknown = 1 while variables: var = variables.pop(0) if var in uniquevars or var == '': var = 'F' + str(unknown) unknown += 1 uniquevars.append(str(var)) firstrow = row + 1 break self.__sheetnames__.append(i) self.__sheets__.setdefault(i,{}).__setitem__('rows',sheet.nrows) self.__sheets__.setdefault(i,{}).__setitem__('cols',sheet.ncols) self.__sheets__.setdefault(i,{}).__setitem__('firstrow',firstrow) self.__sheets__.setdefault(i,{}).__setitem__('variables',uniquevars[:]) def getiter(self, sheetname, returnlist=False, returntupledate=False): """ Return an generator object which yields the lines of a worksheet; Default returns a dictionary, specifing returnlist=True causes lists to be returned. Calling returntupledate=True causes dates to returned as tuples of (Year, Month, Day, Hour, Min, Second) instead of as a string """ if sheetname not in self.__sheets__.keys(): raise NameError, "%s is not present in %s" % (sheetname,\ self.__filename__) if returnlist: return __iterlist__(self, sheetname, returntupledate) else: return __iterdict__(self, sheetname, returntupledate) def worksheets(self): """ Returns a list of the Worksheets in the Excel File """ return self.__sheetnames__ def nrows(self, worksheet): """ Return the number of rows in a worksheet """ return self.__sheets__[worksheet]['rows'] def ncols(self, worksheet): """ Return the number of columns in a worksheet """ return self.__sheets__[worksheet]['cols'] def variables(self,worksheet): """ Returns a list of Column Names in the file, assuming a tabular format of course. """ return self.__sheets__[worksheet]['variables'] def __formatrow__(self, types, values, wanttupledate): """ Internal function used to clean up the incoming excel data """ ## Data Type Codes: ## EMPTY 0 ## TEXT 1 a Unicode string ## NUMBER 2 float ## DATE 3 float ## BOOLEAN 4 int; 1 means TRUE, 0 means FALSE ## ERROR 5 #import xlrd returnrow = [] for i in range(len(types)): type,value = types[i],values[i] if type == 2: if value == int(value): value = int(value) elif type == 3: datetuple = xlrd.xldate_as_tuple(value, self.__book__.datemode) if wanttupledate: value = datetuple else: # time only no date component if datetuple[0] == 0 and datetuple[1] == 0 and \ datetuple[2] == 0: value = "%02d:%02d:%02d" % datetuple[3:] # date only, no time elif datetuple[3] == 0 and datetuple[4] == 0 and \ datetuple[5] == 0: value = "%04d/%02d/%02d" % datetuple[:3] else: # full date value = "%04d/%02d/%02d %02d:%02d:%02d" % datetuple elif type == 5: value = xlrd.error_text_from_code[value] returnrow.append(value) return returnrow def __iterlist__(excel, sheetname, tupledate): """ Function Used To Create the List Iterator """ sheet = excel.__book__.sheet_by_name(sheetname) for row in range(excel.__sheets__[sheetname]['rows']): types,values = sheet.row_types(row),sheet.row_values(row) yield excel.__formatrow__(types, values, tupledate) def __iterdict__(excel, sheetname, tupledate): """ Function Used To Create the Dictionary Iterator """ sheet = excel.__book__.sheet_by_name(sheetname) for row in range(excel.__sheets__[sheetname]['firstrow'],\ excel.__sheets__[sheetname]['rows']): types,values = sheet.row_types(row),sheet.row_values(row) formattedrow = excel.__formatrow__(types, values, tupledate) # Pad a Short Row With Blanks if Needed for i in range(len(formattedrow),\ len(excel.__sheets__[sheetname]['variables'])): formattedrow.append('') yield dict(zip(excel.__sheets__[sheetname]['variables'],formattedrow)) and in default.aspx.py import System import clr from System.Data import * from System.Web import * from System.Web.UI import * #from IronPython.Hosting import PythonEngine from clr import * import SampleModule import sys #import SampleModule2 #import ExcelModule #from ExcelModule import readexcel from SampleModule import SampleClass from SampleModule import readexcel if sys.version.startswith("IronPython"): # print >> sys.stderr, "...importing encodings" import encodings sys.path.append([r'd:\Python24\Lib',r'd:\Python24\Lib\site-packages\xlrd',]) #sys.path.extend([r,'C:\Program Files\Microsoft IronPython for ASP.NET',r'C:\Program Files\Micrsoft IronPython for ASP.NET\Lib',r'C:\\Program Files\\Microsoft IronPython forASP.NET\\lib\\site-packages',r'D:\\python24\\lib',]) import xlrd as ebook book = ebook.open_workbook('D:\my.xls', encoding_override="none") #book=xlrd.open_workbook("C:\Program Files\Microsoft IronPython for ASP.NET\Lib\site-packages\xlrd\examples:\namesdemo.xls" def Page_Load(): pass _PrivateMethod("1") PublicMethod("2") def _PrivateMethod(text): lblPrivate.Text="private %s" %text def PublicMethod(text): lblPublic.Text="public %s" %text def Private_Click(sender,args): _PrivateMethod("3") def Button1_Click(sender, args): ss = readexcel(dir); print ss book = xlrd.open_workbook('D:\my.xls', encoding_override="cp1252") #sc = SampleClass() #excel=readexcel('D:\my.xls') #sc.TestString = TextBox1.Text #Label1.Text = sc.TestString #Label1.Visible="True" #py=PythonEngine() #values = {'string': 'Hello World'} #mod = py.CreateModule('__main__', values, True) #py.DefaultModule = mod #script = "print string" #py.ExecuteToConsole(script) error-- value can not be null encoding please any one can help me out how can i use xlrd module in Microsoft visual studio 2005 with IronPython(i installed IronPython with Microsoft.net CTP) Praveen Kumar Mahiti Infotech Pvt. Ltd. # 33-34, Hennur Cross Hennur Main Road Bangalore, India - 560043 Mobile: +91 9343297314 Phone: +91 80 4148 5080/1 41150580/1 http://www.mahiti.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From sls at iinet.net.au Tue Feb 12 14:30:02 2008 From: sls at iinet.net.au (Paul Turbett) Date: Tue, 12 Feb 2008 22:30:02 +0900 Subject: [IronPython] Help with Ops.GetAttr Message-ID: <47B19F5A.1050102@iinet.net.au> Hi, I'm attempting to get an attribute from python object from C# using a method like this: public object GetAttr(object pyObject, string name) { ICallerContext context = _pythonEngine.DefaultModule as ICallerContext; object value = Ops.GetAttr( context, pyObject, SymbolTable.StringToId(name)); return value; } where _pythonEngine is a PythonEngine object, pyObject is a python object and name is the attribute I want to get. According to other posts I've seen, this should work, but the first line sets context to null. How to I get a valid context? It seems every way I've read about to get the context (DefaultContext.Default, GetModuleScope) is private, and therefore inaccessible. I'm using IPY 1.1.1 TIA, Paul From dinov at exchange.microsoft.com Tue Feb 12 17:51:49 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Tue, 12 Feb 2008 08:51:49 -0800 Subject: [IronPython] Help with Ops.GetAttr In-Reply-To: <47B19F5A.1050102@iinet.net.au> References: <47B19F5A.1050102@iinet.net.au> Message-ID: <7AD436E4270DD54A94238001769C2227011CF47C9DCB@DF-GRTDANE-MSG.exchange.corp.microsoft.com> You could use Ops.TryGetAttr which doesn't take a context (and flows the default context in for you). -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Paul Turbett Sent: Tuesday, February 12, 2008 5:30 AM To: users at lists.ironpython.com Subject: [IronPython] Help with Ops.GetAttr Hi, I'm attempting to get an attribute from python object from C# using a method like this: public object GetAttr(object pyObject, string name) { ICallerContext context = _pythonEngine.DefaultModule as ICallerContext; object value = Ops.GetAttr( context, pyObject, SymbolTable.StringToId(name)); return value; } where _pythonEngine is a PythonEngine object, pyObject is a python object and name is the attribute I want to get. According to other posts I've seen, this should work, but the first line sets context to null. How to I get a valid context? It seems every way I've read about to get the context (DefaultContext.Default, GetModuleScope) is private, and therefore inaccessible. I'm using IPY 1.1.1 TIA, Paul _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From dinov at exchange.microsoft.com Tue Feb 12 17:54:14 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Tue, 12 Feb 2008 08:54:14 -0800 Subject: [IronPython] Please help me out its very urgent In-Reply-To: <6f7fd6e90802112131n3e74bdbblc1f18a0b82f9e2d7@mail.gmail.com> References: <6f7fd6e90802112131n3e74bdbblc1f18a0b82f9e2d7@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF47C9DCD@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Can you try using the library just from the command line and see what the result is? You might want to try running w/ -X:ExceptionDetail to see where the exception is actually coming from. I tried and was able to open a XLS saved in Office 2003 and earlier format w/o any problems using this library so it's hard to know what's blowing up in all the code below. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Praveen Kumar Sent: Monday, February 11, 2008 9:31 PM To: users at lists.ironpython.com Subject: [IronPython] Please help me out its very urgent I am new for Ironpython for ASP.net, earlier i was using only Visual studio 2005 and struggling with to read excel file without M$ Excel object, bt i could nt get any other object which could read excel sheet. But suddenly i got one Lingfo - Python "xlrd" package for extracting data from Excel files - 0.6.1 final which can read successfully excel sheet as i desired.but the problem is i dont knw hw can i use with IronPython Asp.net(Microsoft IronPython for ASP.NET). i have seperately installed Python2.4.. i tried with python2.4 its working failrly.while installing xlrd it automatically search D:\Python24\, there were no option to configure it nad installed in D:\Python24\Lib\site-packages\. Then i copy the XLRD package and paste C:\Program Files\Microsoft IronPython for ASP.NET\Lib\site-packages\ and wrote the python script ExcelModule.py class readexcel(object): def __init__(self,filename): """ Returns a readexcel object of the specified filename - this may take a little while because the file must be parsed into memory """ import sys sys.path.append('D:\Python24\Lib') sys.path.append('D:\Python24\Lib\site-packages') from xlrd import * print dir(xlrd) return printed import os.path if not os.path.isfile(filename): raise NameError, "%s is not a valid filename" % filename self.__filename__ = filename self.__book__ = xlrd.open_workbook(filename) self.__sheets__ = {} self.__sheetnames__ = [] for i in self.__book__.sheet_names(): uniquevars = [] firstrow = 0 sheet = self.__book__.sheet_by_name(i) for row in range(sheet.nrows): types,values = sheet.row_types(row),sheet.row_values(row) nonblank = False for j in values: if j != '': nonblank=True break if nonblank: # Generate a listing of Unique Variable Names for Use as # Dictionary Keys In Extraction. Duplicate Names will # be replaced with "F#" variables = self.__formatrow__(types,values,False) unknown = 1 while variables: var = variables.pop(0) if var in uniquevars or var == '': var = 'F' + str(unknown) unknown += 1 uniquevars.append(str(var)) firstrow = row + 1 break self.__sheetnames__.append(i) self.__sheets__.setdefault(i,{}).__setitem__('rows',sheet.nrows) self.__sheets__.setdefault(i,{}).__setitem__('cols',sheet.ncols) self.__sheets__.setdefault(i,{}).__setitem__('firstrow',firstrow) self.__sheets__.setdefault(i,{}).__setitem__('variables',uniquevars[:]) def getiter(self, sheetname, returnlist=False, returntupledate=False): """ Return an generator object which yields the lines of a worksheet; Default returns a dictionary, specifing returnlist=True causes lists to be returned. Calling returntupledate=True causes dates to returned as tuples of (Year, Month, Day, Hour, Min, Second) instead of as a string """ if sheetname not in self.__sheets__.keys(): raise NameError, "%s is not present in %s" % (sheetname,\ self.__filename__) if returnlist: return __iterlist__(self, sheetname, returntupledate) else: return __iterdict__(self, sheetname, returntupledate) def worksheets(self): """ Returns a list of the Worksheets in the Excel File """ return self.__sheetnames__ def nrows(self, worksheet): """ Return the number of rows in a worksheet """ return self.__sheets__[worksheet]['rows'] def ncols(self, worksheet): """ Return the number of columns in a worksheet """ return self.__sheets__[worksheet]['cols'] def variables(self,worksheet): """ Returns a list of Column Names in the file, assuming a tabular format of course. """ return self.__sheets__[worksheet]['variables'] def __formatrow__(self, types, values, wanttupledate): """ Internal function used to clean up the incoming excel data """ ## Data Type Codes: ## EMPTY 0 ## TEXT 1 a Unicode string ## NUMBER 2 float ## DATE 3 float ## BOOLEAN 4 int; 1 means TRUE, 0 means FALSE ## ERROR 5 #import xlrd returnrow = [] for i in range(len(types)): type,value = types[i],values[i] if type == 2: if value == int(value): value = int(value) elif type == 3: datetuple = xlrd.xldate_as_tuple(value, self.__book__.datemode) if wanttupledate: value = datetuple else: # time only no date component if datetuple[0] == 0 and datetuple[1] == 0 and \ datetuple[2] == 0: value = "%02d:%02d:%02d" % datetuple[3:] # date only, no time elif datetuple[3] == 0 and datetuple[4] == 0 and \ datetuple[5] == 0: value = "%04d/%02d/%02d" % datetuple[:3] else: # full date value = "%04d/%02d/%02d %02d:%02d:%02d" % datetuple elif type == 5: value = xlrd.error_text_from_code[value] returnrow.append(value) return returnrow def __iterlist__(excel, sheetname, tupledate): """ Function Used To Create the List Iterator """ sheet = excel.__book__.sheet_by_name(sheetname) for row in range(excel.__sheets__[sheetname]['rows']): types,values = sheet.row_types(row),sheet.row_values(row) yield excel.__formatrow__(types, values, tupledate) def __iterdict__(excel, sheetname, tupledate): """ Function Used To Create the Dictionary Iterator """ sheet = excel.__book__.sheet_by_name(sheetname) for row in range(excel.__sheets__[sheetname]['firstrow'],\ excel.__sheets__[sheetname]['rows']): types,values = sheet.row_types(row),sheet.row_values(row) formattedrow = excel.__formatrow__(types, values, tupledate) # Pad a Short Row With Blanks if Needed for i in range(len(formattedrow),\ len(excel.__sheets__[sheetname]['variables'])): formattedrow.append('') yield dict(zip(excel.__sheets__[sheetname]['variables'],formattedrow)) and in default.aspx.py import System import clr from System.Data import * from System.Web import * from System.Web.UI import * #from IronPython.Hosting import PythonEngine from clr import * import SampleModule import sys #import SampleModule2 #import ExcelModule #from ExcelModule import readexcel from SampleModule import SampleClass from SampleModule import readexcel if sys.version.startswith("IronPython"): # print >> sys.stderr, "...importing encodings" import encodings sys.path.append([r'd:\Python24\Lib',r'd:\Python24\Lib\site-packages\xlrd',]) #sys.path.extend([r,'C:\Program Files\Microsoft IronPython for ASP.NET',r'C:\Program Files\Micrsoft IronPython for ASP.NET\Lib',r'C:\\Program Files\\Microsoft IronPython forASP.NET\\lib\\site-packages',r'D:\\python24\\lib',]) import xlrd as ebook book = ebook.open_workbook('D:\my.xls', encoding_override="none") #book=xlrd.open_workbook("C:\Program Files\Microsoft IronPython for ASP.NET\Lib\site-packages\xlrd\examples:\namesdemo.xls" def Page_Load(): pass _PrivateMethod("1") PublicMethod("2") def _PrivateMethod(text): lblPrivate.Text="private %s" %text def PublicMethod(text): lblPublic.Text="public %s" %text def Private_Click(sender,args): _PrivateMethod("3") def Button1_Click(sender, args): ss = readexcel(dir); print ss book = xlrd.open_workbook('D:\my.xls', encoding_override="cp1252") #sc = SampleClass() #excel=readexcel('D:\my.xls') #sc.TestString = TextBox1.Text #Label1.Text = sc.TestString #Label1.Visible="True" #py=PythonEngine() #values = {'string': 'Hello World'} #mod = py.CreateModule('__main__', values, True) #py.DefaultModule = mod #script = "print string" #py.ExecuteToConsole(script) error-- value can not be null encoding please any one can help me out how can i use xlrd module in Microsoft visual studio 2005 with IronPython(i installed IronPython with Microsoft.net CTP) Praveen Kumar Mahiti Infotech Pvt. Ltd. # 33-34, Hennur Cross Hennur Main Road Bangalore, India - 560043 Mobile: +91 9343297314 Phone: +91 80 4148 5080/1 41150580/1 http://www.mahiti.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Tue Feb 12 23:50:28 2008 From: sjmachin at lexicon.net (John Machin) Date: Wed, 13 Feb 2008 09:50:28 +1100 Subject: [IronPython] Please help me out its very urgent In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF47C9DCD@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <6f7fd6e90802112131n3e74bdbblc1f18a0b82f9e2d7@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF47C9DCD@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <47B222B4.4050704@lexicon.net> Dino Viehland wrote: > Can you try using the library just from the command line and see what > the result is? You might want to try running w/ -X:ExceptionDetail to > see where the exception is actually coming from. > > > > I tried and was able to open a XLS saved in Office 2003 and earlier > format w/o any problems using this library so it?s hard to know what?s > blowing up in all the code below. Hi Dino, I'm the author of xlrd, the library that Praveen is trying to use. I suspect that the root cause of Praveen's problem is related to this IronPython bug that I reported ages ago: http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=3094 This now says status == closed, and release == 2.0 Alpha 5; however it appears to be fixed in Iron Python 1.1.1. Like you, I have been able to use xlrd OK from the 1.1.1 ipy interactive prompt. Praveen says he can do that too. Praveen is however using "IronPython for ASP.NET" which was evidently released on 11/3/2006 [11 March or 3 November?]. He is *not* using the "ASP.NET Futures" released in May 2007. Caveat: ASP, ASP.NET and "IronPython for ASP.NET" are diminishingly scarce in my knowledge-base :-) Am I correct in guessing that the IronPython bug is not fixed in the 2006 version of "IronPython for ASP.NET"? I have suggested the following to Praveen: """ Please try this simple test: 1. set up a test module called test1.py, containing: import sys print >> sys.stderr, "test 1: being imported" 2. remove all references to xlrd from your aspx.py. Instead, put in: import test1 print >> sys.stderr, "aspx: module imported OK" 3. run that and see if it prints as expected. If print >> sys.stderr doesn't work in IP for asp.net, find some other way of doing debug displays. Do whatever is necessary to get test1 demonstrably importable. 4. copy the final working test1.py to test2.py, and insert a new line at the top: # coding: cp1252 5. change your aspx.py to import test2 instead of test1. If that fails with "Value cannot be null. Parameter name: encoding", then my guess that my reported bug is not fixed in IP for ASP.NET would seem to be correct. We can work around that. """ Unfortunately this was abandoned at step 3, because the aspx.py was missing a line containing "import sys", this caused an error message "name 'sys' not defined", and the suggested remedy caused some further problem of an unspecified nature. > *From:* users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] *On Behalf Of *Praveen Kumar > *Sent:* Monday, February 11, 2008 9:31 PM > *To:* users at lists.ironpython.com > *Subject:* [IronPython] Please help me out its very urgent > > > > I am new for Ironpython for ASP.net, earlier i was using only Visual > studio 2005 and struggling with to read excel file without M$ Excel > object, bt i could nt get any other object which could read excel sheet. > But suddenly i got one > Lingfo ? Python "xlrd" package for extracting data from Excel files ? > 0.6.1 final > which can read successfully excel sheet as i desired.but the problem is > i dont knw hw can i use with IronPython Asp.net(Microsoft IronPython for > ASP.NET ). i have seperately installed Python2.4.. > i tried with python2.4 its working failrly.while installing xlrd it > automatically search D:\Python24\, there were no option to configure it > nad installed in D:\Python24\Lib\site-packages\. > > Then i copy the XLRD package and paste C:\Program Files\Microsoft > IronPython for ASP.NET\Lib\site-packages\ Not at my suggestion :-) > > and wrote the python script ExcelModule.py Actually it's a kludged version of a recipe from the ASPN Python Cookbook ... > > class readexcel(object): > def __init__(self,filename): > """ Returns a readexcel object of the specified filename - this > may take a little while because the file must be parsed into memory """ > import sys > sys.path.append('D:\Python24\Lib') > sys.path.append('D:\Python24\Lib\site-packages') > from xlrd import * > print dir(xlrd) This won't work because "xlrd" is not defined > return printed and this won't work because "printed" is not defined [big snip] > > and in default.aspx.py > > import System > import clr > from System.Data import * > from System.Web import * > from System.Web.UI import * > #from IronPython.Hosting import PythonEngine > from clr import * > import SampleModule > import sys > #import SampleModule2 > #import ExcelModule > #from ExcelModule import readexcel > from SampleModule import SampleClass > from SampleModule import readexcel > if sys.version.startswith("IronPython"): No longer true: IronPython 1.1.1 (1.1.1) on .NET 2.0.50727.832 Copyright (c) Microsoft Corporation. All rights reserved. >>> import sys; sys.version '2.4.0 (IronPython 1.1.1 (1.1.1) on .NET 2.0.50727.832)' >>> > # print >> sys.stderr, "...importing encodings" > import encodings > sys.path.append([r'd:\Python24\Lib',r'd:\Python24\Lib\site-packages\xlrd',]) Should be extend, not append ... > #sys.path.extend([r,'C:\Program Files\Microsoft IronPython for ASP.NET Presumably didn't (definitely won't) work because of the comma ... > ',r'C:\Program Files\Micrsoft IronPython for > ASP.NET\Lib',r'C:\\Program Files\\Microsoft IronPython > forASP.NET\\lib\\site-packages',r'D:\\python24\\lib',]) > import xlrd as ebook > book = ebook.open_workbook('D:\my.xls', encoding_override="none") [snip] > book = xlrd.open_workbook('D:\my.xls', encoding_override="cp1252") WARNING to casual readers: Praveen's problem relates to the use of encoding directives (e.g. #coding: cp1252) at the top of Python source files. The encoding_override argument above has nothing at all to do with this problem. As documented, it is for use in the following corner case: (1) the data file ("my.xls") is in pre-Excel97 format (2) its CODEPAGE record is missing or wrong -- i.e. written by some careless nth-party software developer ... contrary to Darwin's theory, this is not an endangered species :-) Cheers, John From sls at iinet.net.au Wed Feb 13 00:13:02 2008 From: sls at iinet.net.au (Paul Turbett) Date: Wed, 13 Feb 2008 08:13:02 +0900 Subject: [IronPython] Help with Ops.GetAttr In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF47C9DCB@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <47B19F5A.1050102@iinet.net.au> <7AD436E4270DD54A94238001769C2227011CF47C9DCB@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <47B227FE.1020808@iinet.net.au> That did it, thanks! Dino Viehland wrote: > You could use Ops.TryGetAttr which doesn't take a context (and flows the default context in for you). > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Paul Turbett > Sent: Tuesday, February 12, 2008 5:30 AM > To: users at lists.ironpython.com > Subject: [IronPython] Help with Ops.GetAttr > > Hi, > > I'm attempting to get an attribute from python object from C# using a > method like this: > > public object GetAttr(object pyObject, string name) > { > ICallerContext context = _pythonEngine.DefaultModule as ICallerContext; > object value = Ops.GetAttr( context, pyObject, > SymbolTable.StringToId(name)); > return value; > } > > where _pythonEngine is a PythonEngine object, pyObject is a python > object and name is the attribute I want to get. > > According to other posts I've seen, this should work, but the first line > sets context to null. How to I get a valid context? > > It seems every way I've read about to get the context > (DefaultContext.Default, GetModuleScope) is private, and therefore > inaccessible. > > I'm using IPY 1.1.1 > > TIA, Paul > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From dinov at exchange.microsoft.com Wed Feb 13 00:51:41 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Tue, 12 Feb 2008 15:51:41 -0800 Subject: [IronPython] Please help me out its very urgent In-Reply-To: <47B222B4.4050704@lexicon.net> References: <6f7fd6e90802112131n3e74bdbblc1f18a0b82f9e2d7@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF47C9DCD@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47B222B4.4050704@lexicon.net> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4D2692E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Yeah, if it's released in 2006 it looks like it had to be 1.0 (1.1 was released in 2007) - so it's not going to have the fix. I would suggest using ASP.NET Futures if that's possible. Unfortunately I'm not too familiar with the ASP.NET support either and our expert is currently on vacation for the next 2 weeks. I would have thought we would have released a version based upon 1.1 at some point. If we did that it should be possible to drop-in 1.1.1 over the 1.1 binaries and have everything work - but that won't work between 1.0 and 1.1 because the assembly versions are different (which was intentional because there's new public API surface in 1.1). -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of John Machin Sent: Tuesday, February 12, 2008 2:50 PM To: Discussion of IronPython Subject: Re: [IronPython] Please help me out its very urgent Dino Viehland wrote: > Can you try using the library just from the command line and see what > the result is? You might want to try running w/ -X:ExceptionDetail to > see where the exception is actually coming from. > > > > I tried and was able to open a XLS saved in Office 2003 and earlier > format w/o any problems using this library so it's hard to know what's > blowing up in all the code below. Hi Dino, I'm the author of xlrd, the library that Praveen is trying to use. I suspect that the root cause of Praveen's problem is related to this IronPython bug that I reported ages ago: http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=3094 This now says status == closed, and release == 2.0 Alpha 5; however it appears to be fixed in Iron Python 1.1.1. Like you, I have been able to use xlrd OK from the 1.1.1 ipy interactive prompt. Praveen says he can do that too. Praveen is however using "IronPython for ASP.NET" which was evidently released on 11/3/2006 [11 March or 3 November?]. He is *not* using the "ASP.NET Futures" released in May 2007. Caveat: ASP, ASP.NET and "IronPython for ASP.NET" are diminishingly scarce in my knowledge-base :-) Am I correct in guessing that the IronPython bug is not fixed in the 2006 version of "IronPython for ASP.NET"? I have suggested the following to Praveen: """ Please try this simple test: 1. set up a test module called test1.py, containing: import sys print >> sys.stderr, "test 1: being imported" 2. remove all references to xlrd from your aspx.py. Instead, put in: import test1 print >> sys.stderr, "aspx: module imported OK" 3. run that and see if it prints as expected. If print >> sys.stderr doesn't work in IP for asp.net, find some other way of doing debug displays. Do whatever is necessary to get test1 demonstrably importable. 4. copy the final working test1.py to test2.py, and insert a new line at the top: # coding: cp1252 5. change your aspx.py to import test2 instead of test1. If that fails with "Value cannot be null. Parameter name: encoding", then my guess that my reported bug is not fixed in IP for ASP.NET would seem to be correct. We can work around that. """ Unfortunately this was abandoned at step 3, because the aspx.py was missing a line containing "import sys", this caused an error message "name 'sys' not defined", and the suggested remedy caused some further problem of an unspecified nature. > *From:* users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] *On Behalf Of *Praveen Kumar > *Sent:* Monday, February 11, 2008 9:31 PM > *To:* users at lists.ironpython.com > *Subject:* [IronPython] Please help me out its very urgent > > > > I am new for Ironpython for ASP.net, earlier i was using only Visual > studio 2005 and struggling with to read excel file without M$ Excel > object, bt i could nt get any other object which could read excel sheet. > But suddenly i got one > Lingfo - Python "xlrd" package for extracting data from Excel files - > 0.6.1 final > which can read successfully excel sheet as i desired.but the problem is > i dont knw hw can i use with IronPython Asp.net(Microsoft IronPython for > ASP.NET ). i have seperately installed Python2.4.. > i tried with python2.4 its working failrly.while installing xlrd it > automatically search D:\Python24\, there were no option to configure it > nad installed in D:\Python24\Lib\site-packages\. > > Then i copy the XLRD package and paste C:\Program Files\Microsoft > IronPython for ASP.NET\Lib\site-packages\ Not at my suggestion :-) > > and wrote the python script ExcelModule.py Actually it's a kludged version of a recipe from the ASPN Python Cookbook ... > > class readexcel(object): > def __init__(self,filename): > """ Returns a readexcel object of the specified filename - this > may take a little while because the file must be parsed into memory """ > import sys > sys.path.append('D:\Python24\Lib') > sys.path.append('D:\Python24\Lib\site-packages') > from xlrd import * > print dir(xlrd) This won't work because "xlrd" is not defined > return printed and this won't work because "printed" is not defined [big snip] > > and in default.aspx.py > > import System > import clr > from System.Data import * > from System.Web import * > from System.Web.UI import * > #from IronPython.Hosting import PythonEngine > from clr import * > import SampleModule > import sys > #import SampleModule2 > #import ExcelModule > #from ExcelModule import readexcel > from SampleModule import SampleClass > from SampleModule import readexcel > if sys.version.startswith("IronPython"): No longer true: IronPython 1.1.1 (1.1.1) on .NET 2.0.50727.832 Copyright (c) Microsoft Corporation. All rights reserved. >>> import sys; sys.version '2.4.0 (IronPython 1.1.1 (1.1.1) on .NET 2.0.50727.832)' >>> > # print >> sys.stderr, "...importing encodings" > import encodings > sys.path.append([r'd:\Python24\Lib',r'd:\Python24\Lib\site-packages\xlrd',]) Should be extend, not append ... > #sys.path.extend([r,'C:\Program Files\Microsoft IronPython for ASP.NET Presumably didn't (definitely won't) work because of the comma ... > ',r'C:\Program Files\Micrsoft IronPython for > ASP.NET\Lib',r'C:\\Program Files\\Microsoft IronPython > forASP.NET\\lib\\site-packages',r'D:\\python24\\lib',]) > import xlrd as ebook > book = ebook.open_workbook('D:\my.xls', encoding_override="none") [snip] > book = xlrd.open_workbook('D:\my.xls', encoding_override="cp1252") WARNING to casual readers: Praveen's problem relates to the use of encoding directives (e.g. #coding: cp1252) at the top of Python source files. The encoding_override argument above has nothing at all to do with this problem. As documented, it is for use in the following corner case: (1) the data file ("my.xls") is in pre-Excel97 format (2) its CODEPAGE record is missing or wrong -- i.e. written by some careless nth-party software developer ... contrary to Darwin's theory, this is not an endangered species :-) Cheers, John _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From slide.o.mix at gmail.com Wed Feb 13 00:53:13 2008 From: slide.o.mix at gmail.com (Slide) Date: Tue, 12 Feb 2008 16:53:13 -0700 Subject: [IronPython] Parsing Stack Traces Message-ID: I have a current script engine I wrote which deals with CodeDom for JScript.NET scripts and I am currently adding Python capabilities to it. On the JScript.NET side, I can get the CompilerErrors from the CompileResults after I've compiled and run the main entry point of the script. On the Python side, when I run it, I get SyntaxErrorExceptions, etc that I would like to turn into something like a CompilerError object. I wrote my own object that is very similar to CompilerError so that I could abstract this out. Is there a way to get the line number, column number, etc from the Python engine so I could fill these items in? Thanks -- slide-o-blog http://slide-o-blog.blogspot.com/ From praveen at mahiti.org Wed Feb 13 05:29:18 2008 From: praveen at mahiti.org (Praveen Kumar) Date: Wed, 13 Feb 2008 09:59:18 +0530 Subject: [IronPython] Import xlrd Message-ID: <6f7fd6e90802122029g692a9059k2cdc38faf4212c84@mail.gmail.com> Ok, now i am too much confused, tried with different way as possible. Now my simple question is-- May i use xlrd module ItonPython for ASP.Net CTP(1.0) if i can then please tell me the brief information about configuration,library,class....etc or i may use ASP.Net futures then how can i make it possible with this. -- Praveen Kumar Mahiti Infotech Pvt. Ltd. # 33-34, Hennur Cross Hennur Main Road Bangalore, India - 560043 Mobile: +91 9343297314 Phone: +91 80 4148 5080/1 41150580/1 http://www.mahiti.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From barrycarr at ixian-software.com Wed Feb 13 19:36:43 2008 From: barrycarr at ixian-software.com (Barry Carr) Date: Wed, 13 Feb 2008 18:36:43 +0000 Subject: [IronPython] v1.1.1: Problem loading assembly, I think Message-ID: <47B338BB.7040406@ixian-software.com> Hi, My apologies if this is really obvious but I'm stumped. The cut down python file below is called from a C# windows form app (.NET 2.0). When it runs it fails and reports: "Name 'Regex' not defined". Stepping through the python code shows that it fails as soon as comes across the first use of the Regex class. I've tried running the script with ipy and I get the same result. I've also tried to import RE. That worked in ipy but failed with the same error when the script was run via the hosting app. import System import clr from System.Text.RegularExpressions import * class SmartPadToDisplayIT: "Description of Class" def __init__(self, srcFile, destFile): self.template = [] self.sourceData = {} self.srcFile = srcFile self.destFile = destFile self.TokenExpression = Regex("{(.+)}$", RegexOptions.Compiled) def Convert(self): pass converter = SmartPadToDisplayIT(sourceFile, destinationFile) converter.Convert() the thing the gets me is that this used to work. Has something change between 1.0 and 1.1 or 1.1 and 1.1.1? Or have not set up the PythonEngine correctly in my app? Here is the C# code that sets up the engine: public frmConvertSurveys() { InitializeComponent(); codeBasePath = Platform.GetPath(Assembly.GetExecutingAssembly()); EngineOptions opts = new EngineOptions(); opts.ClrDebuggingEnabled = true; opts.ExceptionDetail = true; opts.ShowClrExceptions = true; pyEngine = new PythonEngine(opts); InitializePythonEngine(); CheckEssentialFilesPresent(); } private void InitializePythonEngine() { pyEngine.Import( "site" ); pyEngine.Import( "clr" ); //pyEngine.AddToPath( ".\\" ); //pyEngine.AddToPath( codeBasePath ); } And, finally, here is the code where the script is called: private void RunPythonScript() { Dictionary fileParameters = new Dictionary(); EngineModule module = pyEngine.CreateModule(); //CompiledCode code = pyEngine.CompileFile(".\\SmartPad2DisplayIT.py"); CompiledCode code = pyEngine.CompileFile(".\\SP2DIY.py"); fileParameters.Add( "sourceFile", string.Empty); fileParameters.Add( "destinationFile", string.Empty); try { pbConversion.Maximum = conversionList.Count; pbConversion.Minimum = 0; pbConversion.Value = 0; foreach( ConversionInfo ci in conversionList ) { UpdateFeedback(string.Format("Converting {0} to {1}", ci.Source, ci.Destination)); fileParameters["sourceFile"] = ci.Source; fileParameters["destinationFile"] = ci.Destination; code.Execute(module, fileParameters); pbConversion.Increment(1); } } catch( PythonNameErrorException pne ) { UpdateFeedback("*** Python Engine reports ***", "*** " + pne.Message + " ***"); } catch( Exception ex ) { UpdateFeedback("*** Unexpected Error ***", "*** " + ex.Message + " ***"); } } If anyone can shed any light on this I'd be most grateful. Thanks. Cheers Barry Carr From dinov at exchange.microsoft.com Wed Feb 13 20:28:11 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 13 Feb 2008 11:28:11 -0800 Subject: [IronPython] v1.1.1: Problem loading assembly, I think In-Reply-To: <47B338BB.7040406@ixian-software.com> References: <47B338BB.7040406@ixian-software.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4D26ADB@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Does this simple case work for you? It works for me on 1.0, 1.1, and 1.1.1: Test.cs: using System; using IronPython.Hosting; public class Foo { public static void Main(string[]args) { PythonEngine pe = new PythonEngine(); EngineModule module = pe.CreateModule(); CompiledCode code = pe.CompileFile(".\\foo.py"); code.Execute(module); } } foo.py: from System.Text.RegularExpressions import * print dir() print Regex The only thing that I could think of that would cause this to break is if we somehow failed to add the reference to System.dll - but we do that by default so that shouldn't be possible to break. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Barry Carr Sent: Wednesday, February 13, 2008 10:37 AM To: users at lists.ironpython.com Subject: [IronPython] v1.1.1: Problem loading assembly, I think Hi, My apologies if this is really obvious but I'm stumped. The cut down python file below is called from a C# windows form app (.NET 2.0). When it runs it fails and reports: "Name 'Regex' not defined". Stepping through the python code shows that it fails as soon as comes across the first use of the Regex class. I've tried running the script with ipy and I get the same result. I've also tried to import RE. That worked in ipy but failed with the same error when the script was run via the hosting app. import System import clr from System.Text.RegularExpressions import * class SmartPadToDisplayIT: "Description of Class" def __init__(self, srcFile, destFile): self.template = [] self.sourceData = {} self.srcFile = srcFile self.destFile = destFile self.TokenExpression = Regex("{(.+)}$", RegexOptions.Compiled) def Convert(self): pass converter = SmartPadToDisplayIT(sourceFile, destinationFile) converter.Convert() the thing the gets me is that this used to work. Has something change between 1.0 and 1.1 or 1.1 and 1.1.1? Or have not set up the PythonEngine correctly in my app? Here is the C# code that sets up the engine: public frmConvertSurveys() { InitializeComponent(); codeBasePath = Platform.GetPath(Assembly.GetExecutingAssembly()); EngineOptions opts = new EngineOptions(); opts.ClrDebuggingEnabled = true; opts.ExceptionDetail = true; opts.ShowClrExceptions = true; pyEngine = new PythonEngine(opts); InitializePythonEngine(); CheckEssentialFilesPresent(); } private void InitializePythonEngine() { pyEngine.Import( "site" ); pyEngine.Import( "clr" ); //pyEngine.AddToPath( ".\\" ); //pyEngine.AddToPath( codeBasePath ); } And, finally, here is the code where the script is called: private void RunPythonScript() { Dictionary fileParameters = new Dictionary(); EngineModule module = pyEngine.CreateModule(); //CompiledCode code = pyEngine.CompileFile(".\\SmartPad2DisplayIT.py"); CompiledCode code = pyEngine.CompileFile(".\\SP2DIY.py"); fileParameters.Add( "sourceFile", string.Empty); fileParameters.Add( "destinationFile", string.Empty); try { pbConversion.Maximum = conversionList.Count; pbConversion.Minimum = 0; pbConversion.Value = 0; foreach( ConversionInfo ci in conversionList ) { UpdateFeedback(string.Format("Converting {0} to {1}", ci.Source, ci.Destination)); fileParameters["sourceFile"] = ci.Source; fileParameters["destinationFile"] = ci.Destination; code.Execute(module, fileParameters); pbConversion.Increment(1); } } catch( PythonNameErrorException pne ) { UpdateFeedback("*** Python Engine reports ***", "*** " + pne.Message + " ***"); } catch( Exception ex ) { UpdateFeedback("*** Unexpected Error ***", "*** " + ex.Message + " ***"); } } If anyone can shed any light on this I'd be most grateful. Thanks. Cheers Barry Carr _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From dinov at exchange.microsoft.com Wed Feb 13 20:42:14 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 13 Feb 2008 11:42:14 -0800 Subject: [IronPython] Import xlrd In-Reply-To: <6f7fd6e90802122029g692a9059k2cdc38faf4212c84@mail.gmail.com> References: <6f7fd6e90802122029g692a9059k2cdc38faf4212c84@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4D26AED@DF-GRTDANE-MSG.exchange.corp.microsoft.com> It seems like the simple answer is no - that version of IronPython is too old and has a bug which prevents xlrd from working. The ASP.NET Futures package may have a recent enough version that it works. Using ASP.NET futures it should be as simple as doing a sys.path.append('location_of_xlrd') then import xlrd and continue normally from there. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Praveen Kumar Sent: Tuesday, February 12, 2008 8:29 PM To: Users at lists.ironpython.com Subject: [IronPython] Import xlrd Ok, now i am too much confused, tried with different way as possible. Now my simple question is-- May i use xlrd module ItonPython for ASP.Net CTP(1.0) if i can then please tell me the brief information about configuration,library,class....etc or i may use ASP.Net futures then how can i make it possible with this. -- Praveen Kumar Mahiti Infotech Pvt. Ltd. # 33-34, Hennur Cross Hennur Main Road Bangalore, India - 560043 Mobile: +91 9343297314 Phone: +91 80 4148 5080/1 41150580/1 http://www.mahiti.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Wed Feb 13 21:25:38 2008 From: sjmachin at lexicon.net (John Machin) Date: Thu, 14 Feb 2008 07:25:38 +1100 Subject: [IronPython] Import xlrd In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF4D26AED@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <6f7fd6e90802122029g692a9059k2cdc38faf4212c84@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4D26AED@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <47B35242.6040808@lexicon.net> Dino Viehland wrote: > It seems like the simple answer is no ? that version of IronPython is > too old and has a bug which prevents xlrd from working. The ASP.NET > Futures package may have a recent enough version that it works. > > > > Using ASP.NET futures it should be as simple as doing a > sys.path.append(?location_of_xlrd?) then import xlrd and continue > normally from there. > Dino, to cater for the possibility that xlrd imports CPython modules that are not supported by IronPython, would be safer to add the Cpython Lib directory to sys.path also? Alternatively: xlrd uses "# coding: cp1252" only for "copyright" and "trademark" symbols -- these could be ripped out. Over to you, Praveen -- if you can demonstrate that you can write a minimal aspx.py that imports a minimal_no_coding_declaration.py module successfully, I'll ship you a version of xlrd with no "# coding: cp1252" and no non-ASCII characters in the source files. Cheers, John From rpigneri at LavaStorm.com Wed Feb 13 22:00:36 2008 From: rpigneri at LavaStorm.com (Pigneri, Rocco) Date: Wed, 13 Feb 2008 16:00:36 -0500 Subject: [IronPython] ipy.exe as a Compiler Message-ID: Dear all, I am trying to use ipy.exe as a compiler to compile automatically nightly builds using a make-like build tool, and I was having some difficulty getting it to work. First, I'll lay out what I am trying to accomplish, and then lay out my questions. I want to be able to organize a large product into different projects, each located in a separate directory. Projects that are made only to serve another project are in subdirectories of the dependent project. In other words, if A depends on B and C, B and C would be in separate directories off of A's directory. I would ideally like to compile B and C into DLL's and A into an EXE assembly or compile them all into one large executable assembly. So, first question: is this a properly Pythonic way to go about doing things? I'm pretty new to Python so it's possible that I'm trying to use my C#/Java experience in a negative way here. Second, can I change the name of the target? In other words, is there an option like -o from gcc? Third, can I create DLL's with ipy.exe or am I forced to always create executable assemblies? It would be nice if I could compile all my subprojects into separate assemblies and then make the "top level" one be the one EXE. Fourth, can I reference assemblies in more than one directory when building an EXE? If A depends on only B, I can provide the path to B via -X:AssembliesDir directive, and then everything is built in one assembly using whatever Python files are found in the AssembliesDir and the current directory. However, if A depends on B and C, then providing two paths in the -X:AssembliesDir switch--separated by a colon or semicolon--produces an error, and providing two switches means that only the final one is used. Fifth, using -X:AssembliesDir and -X:SaveAssembly always seems to run the assemblies out of the AssembliesDir directory rather than the current directory at the prompt. Is this correct behavior? Sixth, is there a way to compile a script without running it? The -X:SaveAssemblies option runs the script no matter what. It would be useful to turn this off in automated builds. Seventh, there seems to be some sort of dependency built into IPY assemblies regarding assembly names. If A depends on B, for example, then I can compile A and B separately (A complains that it cannot find B), put all the assemblies in one directory, and run everything without any problem. I can even rename B.exe to B.dll and still run A.exe. However, if I repeat the same process when A depends on B and C, A.exe fails to run, regardless of the names of other assemblies. Could someone help me understand what is going on here? Finally, is there documentation somewhere about all the -X compiler switches? Googling for a few of them seemed only to lead me to some e-mails about them rather than to any formal documenation. Sorry for the huge e-mail, but after searching for information for two days, I have more questions than when I started :-). I guess that means I'm learning :-). Thank you, Rocco -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Wed Feb 13 22:23:54 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 13 Feb 2008 13:23:54 -0800 Subject: [IronPython] Parsing Stack Traces In-Reply-To: References: Message-ID: <7AD436E4270DD54A94238001769C2227011CF4D26B47@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Are you using the Python code dom provider from 1.x or directly interacting w/ the hosting APIs? I think you should get a list of errors like you'd normally get w/ CodeDom - although it'll probably only include 1 error (but it should have line info). Otherwise in 1.x you can subclass the CompilerSink class and set your own sink on PythonCompiler and have all the errors provided to you. When AddError on the sink gets called you'll get a CodeSpan and the text of the line. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Slide Sent: Tuesday, February 12, 2008 3:53 PM To: Discussion of IronPython Subject: [IronPython] Parsing Stack Traces I have a current script engine I wrote which deals with CodeDom for JScript.NET scripts and I am currently adding Python capabilities to it. On the JScript.NET side, I can get the CompilerErrors from the CompileResults after I've compiled and run the main entry point of the script. On the Python side, when I run it, I get SyntaxErrorExceptions, etc that I would like to turn into something like a CompilerError object. I wrote my own object that is very similar to CompilerError so that I could abstract this out. Is there a way to get the line number, column number, etc from the Python engine so I could fill these items in? Thanks -- slide-o-blog http://slide-o-blog.blogspot.com/ _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From dinov at exchange.microsoft.com Wed Feb 13 22:39:11 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 13 Feb 2008 13:39:11 -0800 Subject: [IronPython] Import xlrd In-Reply-To: <47B35242.6040808@lexicon.net> References: <6f7fd6e90802122029g692a9059k2cdc38faf4212c84@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4D26AED@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47B35242.6040808@lexicon.net> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4D26B5E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Yeah, adding Lib to sys.path will definitely also be necessary. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of John Machin Sent: Wednesday, February 13, 2008 12:26 PM To: Discussion of IronPython Subject: Re: [IronPython] Import xlrd Dino Viehland wrote: > It seems like the simple answer is no - that version of IronPython is > too old and has a bug which prevents xlrd from working. The ASP.NET > Futures package may have a recent enough version that it works. > > > > Using ASP.NET futures it should be as simple as doing a > sys.path.append('location_of_xlrd') then import xlrd and continue > normally from there. > Dino, to cater for the possibility that xlrd imports CPython modules that are not supported by IronPython, would be safer to add the Cpython Lib directory to sys.path also? Alternatively: xlrd uses "# coding: cp1252" only for "copyright" and "trademark" symbols -- these could be ripped out. Over to you, Praveen -- if you can demonstrate that you can write a minimal aspx.py that imports a minimal_no_coding_declaration.py module successfully, I'll ship you a version of xlrd with no "# coding: cp1252" and no non-ASCII characters in the source files. Cheers, John _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From slide.o.mix at gmail.com Wed Feb 13 22:54:19 2008 From: slide.o.mix at gmail.com (Slide) Date: Wed, 13 Feb 2008 14:54:19 -0700 Subject: [IronPython] Parsing Stack Traces In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF4D26B47@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <7AD436E4270DD54A94238001769C2227011CF4D26B47@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: I am using the 2.0 hosting APIs. I'll look around some more in the code. I have a situation which works now using FormatException that should work ok. thanks slide On Feb 13, 2008 2:23 PM, Dino Viehland wrote: > Are you using the Python code dom provider from 1.x or directly interacting w/ the hosting APIs? I think you should get a list of errors like you'd normally get w/ CodeDom - although it'll probably only include 1 error (but it should have line info). > > Otherwise in 1.x you can subclass the CompilerSink class and set your own sink on PythonCompiler and have all the errors provided to you. When AddError on the sink gets called you'll get a CodeSpan and the text of the line. > > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Slide > Sent: Tuesday, February 12, 2008 3:53 PM > To: Discussion of IronPython > Subject: [IronPython] Parsing Stack Traces > > I have a current script engine I wrote which deals with CodeDom for > JScript.NET scripts and I am currently adding Python capabilities to > it. On the JScript.NET side, I can get the CompilerErrors from the > CompileResults after I've compiled and run the main entry point of the > script. On the Python side, when I run it, I get > SyntaxErrorExceptions, etc that I would like to turn into something > like a CompilerError object. I wrote my own object that is very > similar to CompilerError so that I could abstract this out. Is there a > way to get the line number, column number, etc from the Python engine > so I could fill these items in? > > Thanks > > -- > slide-o-blog > http://slide-o-blog.blogspot.com/ > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > -- slide-o-blog http://slide-o-blog.blogspot.com/ From dinov at exchange.microsoft.com Wed Feb 13 23:14:42 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 13 Feb 2008 14:14:42 -0800 Subject: [IronPython] Parsing Stack Traces In-Reply-To: References: <7AD436E4270DD54A94238001769C2227011CF4D26B47@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4D26BA4@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Ahh, in that case the class to subclass is ErrorSink instead of CompilerSink :) Once you have an error sink you can call: ScriptEngine.Compile(source, compilerOptions, errorSink) And your sink should get notified of the errors. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Slide Sent: Wednesday, February 13, 2008 1:54 PM To: Discussion of IronPython Subject: Re: [IronPython] Parsing Stack Traces I am using the 2.0 hosting APIs. I'll look around some more in the code. I have a situation which works now using FormatException that should work ok. thanks slide On Feb 13, 2008 2:23 PM, Dino Viehland wrote: > Are you using the Python code dom provider from 1.x or directly interacting w/ the hosting APIs? I think you should get a list of errors like you'd normally get w/ CodeDom - although it'll probably only include 1 error (but it should have line info). > > Otherwise in 1.x you can subclass the CompilerSink class and set your own sink on PythonCompiler and have all the errors provided to you. When AddError on the sink gets called you'll get a CodeSpan and the text of the line. > > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Slide > Sent: Tuesday, February 12, 2008 3:53 PM > To: Discussion of IronPython > Subject: [IronPython] Parsing Stack Traces > > I have a current script engine I wrote which deals with CodeDom for > JScript.NET scripts and I am currently adding Python capabilities to > it. On the JScript.NET side, I can get the CompilerErrors from the > CompileResults after I've compiled and run the main entry point of the > script. On the Python side, when I run it, I get > SyntaxErrorExceptions, etc that I would like to turn into something > like a CompilerError object. I wrote my own object that is very > similar to CompilerError so that I could abstract this out. Is there a > way to get the line number, column number, etc from the Python engine > so I could fill these items in? > > Thanks > > -- > slide-o-blog > http://slide-o-blog.blogspot.com/ > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > -- slide-o-blog http://slide-o-blog.blogspot.com/ _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From barrycarr at ixian-software.com Thu Feb 14 12:06:42 2008 From: barrycarr at ixian-software.com (Barry Carr) Date: Thu, 14 Feb 2008 11:06:42 +0000 Subject: [IronPython] v1.1.1: Problem loading assembly, I think In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF4D26ADB@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <47B338BB.7040406@ixian-software.com> <7AD436E4270DD54A94238001769C2227011CF4D26ADB@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <47B420C2.10201@ixian-software.com> Hi Dino, Dino Viehland wrote: > Does this simple case work for you? It works for me on 1.0, 1.1, and 1.1.1: > Yes, it works fine. Cheers Barry Carr From barrycarr at ixian-software.com Thu Feb 14 13:55:33 2008 From: barrycarr at ixian-software.com (Barry Carr) Date: Thu, 14 Feb 2008 12:55:33 +0000 Subject: [IronPython] v1.1.1: Problem loading assembly, I think In-Reply-To: <47B420C2.10201@ixian-software.com> References: <47B338BB.7040406@ixian-software.com> <7AD436E4270DD54A94238001769C2227011CF4D26ADB@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47B420C2.10201@ixian-software.com> Message-ID: <47B43A45.4050202@ixian-software.com> Hi, After a little more experimentation and building on Dino's example, it looks like my __init__ method/constructor can see any outer scopes. If I add the import statement to the __init__ method then the Regex class is found: class SmartPadToDisplayIT: "Description of Class" print dir() def __init__(self, srcFile, destFile): from System.Text.RegularExpressions import Regex, RegexOptions print dir() self.template = [] self.sourceData = {} self.srcFile = srcFile self.destFile = destFile self.TokenExpression = Regex("{(.+)}$", RegexOptions.Compiled) print self.TokenExpression ... Surely, this can't be right? Cheers Barry Carr Barry Carr wrote: > Hi Dino, > > Dino Viehland wrote: >> Does this simple case work for you? It works for me on 1.0, 1.1, and 1.1.1: >> > Yes, it works fine. > > Cheers > Barry Carr > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From barrycarr at ixian-software.com Thu Feb 14 18:58:09 2008 From: barrycarr at ixian-software.com (Barry Carr) Date: Thu, 14 Feb 2008 17:58:09 +0000 Subject: [IronPython] v1.1.1: Problem loading assembly, I think In-Reply-To: <47B43A45.4050202@ixian-software.com> References: <47B338BB.7040406@ixian-software.com> <7AD436E4270DD54A94238001769C2227011CF4D26ADB@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47B420C2.10201@ixian-software.com> <47B43A45.4050202@ixian-software.com> Message-ID: <47B48131.5030401@ixian-software.com> Hi, I've figured it out and got it working. I created a module and made sure that it was published and that seems to have been the answer. Thanks Dino for pointing me in the right direction. Cheer Barry Carr From rpigneri at LavaStorm.com Thu Feb 14 23:09:38 2008 From: rpigneri at LavaStorm.com (Pigneri, Rocco) Date: Thu, 14 Feb 2008 17:09:38 -0500 Subject: [IronPython] Compilation and ipy.exe Message-ID: Dear all, Is there a way to make IronPython import module files with extensions other than "py"? For example, I would like to be able to name a file "foo.ipy" to indicate that it's an IronPython file that is dependent upon .NET. I would then like to import it using "import foo" without having to override __import__--that sounds like a lot of work just to add an extension :-(. The goal of this is to be able to easily differentiate files that are pure-CPython but used by IronPython from those are cannot run without it. Thank you, Rocco -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at voidspace.org.uk Fri Feb 15 12:31:52 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Fri, 15 Feb 2008 11:31:52 +0000 Subject: [IronPython] Compilation and ipy.exe In-Reply-To: References: Message-ID: <47B57828.4000206@voidspace.org.uk> Pigneri, Rocco wrote: > Dear all, > > Is there a way to make IronPython import module files with extensions > other than "py"? For example, I would like to be able to name a file > "foo.ipy" to indicate that it's an IronPython file that is dependent > upon .NET. I would then like to import it using "import foo" without > having to override __import__--that sounds like a lot of work just to > add an extension :-(. > > The goal of this is to be able to easily differentiate files that are > pure-CPython but used by IronPython from those are cannot run without it. You can install import hooks to customize the import process. This is just as much work (more) as overriding '__import__' but looks 'seamless' in code that uses it. Unfortunately import hooks don't seem to work very well in IronPython 1 but I think they work better in IronPython 2. There is an example of an import hook in FePy for using C extensions from IronPython - it installs a hook that lets you import '.pyd' files. Michael http://www.manning.com/foord > > Thank you, > > Rocco > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From anakinnani at hotmail.com Fri Feb 15 17:09:47 2008 From: anakinnani at hotmail.com (jane janet) Date: Fri, 15 Feb 2008 16:09:47 +0000 Subject: [IronPython] OpenGL with IronPython Message-ID: Hi all, I need help again. I don't know how to use OpenGL in IronPython. I want to draw the line in IronPython application. Please teach me clearly. All the best, Jane Jane _________________________________________________________________ Connect and share in new ways with Windows Live. http://www.windowslive.com/share.html?ocid=TXT_TAGHM_Wave2_sharelife_012008 -------------- next part -------------- An HTML attachment was scrubbed... URL: From Jon.Cooper at arrowgrass.com Fri Feb 15 17:28:33 2008 From: Jon.Cooper at arrowgrass.com (Jon Cooper) Date: Fri, 15 Feb 2008 16:28:33 +0000 Subject: [IronPython] OpenGL with IronPython In-Reply-To: References: Message-ID: <7847E919C98EA24E8777BA06ACD17A1635D73F@aglonexh01.arrowgrass.local> Perhaps you should use Processing instead? http://www.processing.org/ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of jane janet Sent: Friday, February 15, 2008 11:10 AM To: users at lists.ironpython.com Subject: [IronPython] OpenGL with IronPython Hi all, I need help again. I don't know how to use OpenGL in IronPython. I want to draw the line in IronPython application. Please teach me clearly. All the best, Jane [cid:image001.jpg at 01C86FC5.E6007810][cid:image001.jpg at 01C86FC5.E6007810]Jane[cid:image001.jpg at 01C86FC5.E6007810][cid:image001.jpg at 01C86FC5.E6007810][cid:image001.jpg at 01C86FC5.E6007810] ________________________________ Connect and share in new ways with Windows Live. Get it now! ________________________________ Arrowgrass Capital Partners (US) LP is a limited partnership registered in the State of Delaware. This message is for the named person's use only. It may contain confidential, proprietary or legally privileged information. No confidentiality or privilege is waived or lost by any transmission errors. If you receive this message in error, please immediately delete it and all copies of it from your system, destroy any hard copies of it and notify the sender. You must not, directly or indirectly, use, disclose, distribute, print, or copy any part of this message if you are not the intended recipient. -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 338 bytes Desc: image001.jpg URL: From rpigneri at LavaStorm.com Fri Feb 15 17:38:00 2008 From: rpigneri at LavaStorm.com (Pigneri, Rocco) Date: Fri, 15 Feb 2008 11:38:00 -0500 Subject: [IronPython] Compilation and ipy.exe In-Reply-To: <47B57828.4000206@voidspace.org.uk> References: <47B57828.4000206@voidspace.org.uk> Message-ID: Michael, Ironically, I actually saw that example yesterday, but I wasn't sure if I should use it since FePy is another implementation of CPython. I'll give that another look today. Do you know if it will work in IronPython unchanged? Thank you, Rocco -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: Friday, February 15, 2008 6:32 AM To: Discussion of IronPython Subject: Re: [IronPython] Compilation and ipy.exe Pigneri, Rocco wrote: > Dear all, > > Is there a way to make IronPython import module files with extensions > other than "py"? For example, I would like to be able to name a file > "foo.ipy" to indicate that it's an IronPython file that is dependent > upon .NET. I would then like to import it using "import foo" without > having to override __import__--that sounds like a lot of work just to > add an extension :-(. > > The goal of this is to be able to easily differentiate files that are > pure-CPython but used by IronPython from those are cannot run without it. You can install import hooks to customize the import process. This is just as much work (more) as overriding '__import__' but looks 'seamless' in code that uses it. Unfortunately import hooks don't seem to work very well in IronPython 1 but I think they work better in IronPython 2. There is an example of an import hook in FePy for using C extensions from IronPython - it installs a hook that lets you import '.pyd' files. Michael http://www.manning.com/foord > > Thank you, > > Rocco > ---------------------------------------------------------------------- > -- > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From rpigneri at LavaStorm.com Fri Feb 15 18:28:07 2008 From: rpigneri at LavaStorm.com (Pigneri, Rocco) Date: Fri, 15 Feb 2008 12:28:07 -0500 Subject: [IronPython] Compiling with Two Dependent Libraries Message-ID: Dear all, If I have two projects, A and B, and A depends on B, then I can compile A and B together into one assembly by using the -X:AssembliesDir directive. Even though the documentation labels this switch as indicating where to put the output assemblies, it also uses whatever IPY files it finds in the AssembliesDir to compile the output assembly. Now, let's say I have three projects A, B, and C. A depends on B and C. If I provide 2 AssembliesDir switches, then only the final one is used to pull in libraries, and the compiler says that it cannot find the first library's code. If I put two directories in the switch--separated by a colon or semicolon--then I get an error. Also, if I try to compile all three projects separately and then put all three assemblies in the same directory, I still cannot run the software. How can I build project A in this case? Thank you, Rocco -------------- next part -------------- An HTML attachment was scrubbed... URL: From dblank at brynmawr.edu Fri Feb 15 18:39:31 2008 From: dblank at brynmawr.edu (Douglas S. Blank) Date: Fri, 15 Feb 2008 12:39:31 -0500 (EST) Subject: [IronPython] Compilation and ipy.exe In-Reply-To: References: <47B57828.4000206@voidspace.org.uk> Message-ID: <35289.71.59.123.159.1203097171.squirrel@webmail.brynmawr.edu> On Fri, February 15, 2008 11:38 am, Pigneri, Rocco said: > Michael, > > Ironically, I actually saw that example yesterday, but I wasn't sure if > I should use it since FePy is another implementation of CPython. I'll > give that another look today. Do you know if it will work in IronPython > unchanged? Rocco, FePy is *not* another implementation of CPython. There isn't much text on http://fepy.sourceforge.net/ but it does say: "FePy project aims to provide enhancements and add-ons for IronPython, an implementation of Python programming language." -Doug > Thank you, > > Rocco > > -----Original Message----- > From: users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord > Sent: Friday, February 15, 2008 6:32 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Compilation and ipy.exe > > Pigneri, Rocco wrote: >> Dear all, >> >> Is there a way to make IronPython import module files with extensions >> other than "py"? For example, I would like to be able to name a file >> "foo.ipy" to indicate that it's an IronPython file that is dependent >> upon .NET. I would then like to import it using "import foo" without >> having to override __import__--that sounds like a lot of work just to >> add an extension :-(. >> >> The goal of this is to be able to easily differentiate files that are >> pure-CPython but used by IronPython from those are cannot run without > it. > > You can install import hooks to customize the import process. This is > just as much work (more) as overriding '__import__' but looks 'seamless' > > in code that uses it. > > Unfortunately import hooks don't seem to work very well in IronPython 1 > but I think they work better in IronPython 2. There is an example of an > import hook in FePy for using C extensions from IronPython - it installs > a hook that lets you import '.pyd' files. > > Michael > http://www.manning.com/foord > >> >> Thank you, >> >> Rocco >> ---------------------------------------------------------------------- >> -- >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > -- Douglas S. Blank Associate Professor, Bryn Mawr College http://cs.brynmawr.edu/~dblank/ Office: 610 526 6501 From rpigneri at LavaStorm.com Fri Feb 15 18:55:40 2008 From: rpigneri at LavaStorm.com (Pigneri, Rocco) Date: Fri, 15 Feb 2008 12:55:40 -0500 Subject: [IronPython] Compilation and ipy.exe In-Reply-To: <35289.71.59.123.159.1203097171.squirrel@webmail.brynmawr.edu> References: <47B57828.4000206@voidspace.org.uk> <35289.71.59.123.159.1203097171.squirrel@webmail.brynmawr.edu> Message-ID: Wow, how on Earth did I miss that? Thanks for pointing that out, Doug. Rocco -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Douglas S. Blank Sent: Friday, February 15, 2008 12:40 PM To: Discussion of IronPython Cc: Discussion of IronPython Subject: Re: [IronPython] Compilation and ipy.exe On Fri, February 15, 2008 11:38 am, Pigneri, Rocco said: > Michael, > > Ironically, I actually saw that example yesterday, but I wasn't sure > if I should use it since FePy is another implementation of CPython. > I'll give that another look today. Do you know if it will work in > IronPython unchanged? Rocco, FePy is *not* another implementation of CPython. There isn't much text on http://fepy.sourceforge.net/ but it does say: "FePy project aims to provide enhancements and add-ons for IronPython, an implementation of Python programming language." -Doug > Thank you, > > Rocco > > -----Original Message----- > From: users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord > Sent: Friday, February 15, 2008 6:32 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Compilation and ipy.exe > > Pigneri, Rocco wrote: >> Dear all, >> >> Is there a way to make IronPython import module files with extensions >> other than "py"? For example, I would like to be able to name a file >> "foo.ipy" to indicate that it's an IronPython file that is dependent >> upon .NET. I would then like to import it using "import foo" without >> having to override __import__--that sounds like a lot of work just to >> add an extension :-(. >> >> The goal of this is to be able to easily differentiate files that are >> pure-CPython but used by IronPython from those are cannot run without > it. > > You can install import hooks to customize the import process. This is > just as much work (more) as overriding '__import__' but looks 'seamless' > > in code that uses it. > > Unfortunately import hooks don't seem to work very well in IronPython > 1 but I think they work better in IronPython 2. There is an example of > an import hook in FePy for using C extensions from IronPython - it > installs a hook that lets you import '.pyd' files. > > Michael > http://www.manning.com/foord > >> >> Thank you, >> >> Rocco >> --------------------------------------------------------------------- >> - >> -- >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > -- Douglas S. Blank Associate Professor, Bryn Mawr College http://cs.brynmawr.edu/~dblank/ Office: 610 526 6501 _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From rpigneri at LavaStorm.com Fri Feb 15 18:57:11 2008 From: rpigneri at LavaStorm.com (Pigneri, Rocco) Date: Fri, 15 Feb 2008 12:57:11 -0500 Subject: [IronPython] Save Assemblies without Running Script Message-ID: Dear all, When I try to save an assembly using -X:SaveAssemblies, the script that I am compiling is also run. Is there a way to save the assemblies without running the script as well? Thank you, Rocco -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Fri Feb 15 19:41:02 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Fri, 15 Feb 2008 10:41:02 -0800 Subject: [IronPython] Save Assemblies without Running Script In-Reply-To: References: Message-ID: <7AD436E4270DD54A94238001769C2227011CF4D26FF4@DF-GRTDANE-MSG.exchange.corp.microsoft.com> The pyc sample available here: http://www.codeplex.com/IronPython/Release/ProjectReleases.aspx?ReleaseId=47 should enable you to do that. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Pigneri, Rocco Sent: Friday, February 15, 2008 9:57 AM To: Discussion of IronPython Subject: [IronPython] Save Assemblies without Running Script Dear all, When I try to save an assembly using -X:SaveAssemblies, the script that I am compiling is also run. Is there a way to save the assemblies without running the script as well? Thank you, Rocco -------------- next part -------------- An HTML attachment was scrubbed... URL: From sh at defuze.org Fri Feb 15 21:37:51 2008 From: sh at defuze.org (Sylvain Hellegouarch) Date: Fri, 15 Feb 2008 20:37:51 +0000 Subject: [IronPython] OpenGL with IronPython In-Reply-To: References: Message-ID: <47B5F81F.4000803@defuze.org> Hi there, You might want to use Tao [1]. The example below works fine with the latest stable release of Tao (2.0.0) and Mono 1.2.6 Note that I'm using Glfw [2] here but you could use FreeGlut instead of course. That example simply renders a spinning triangle onto a window. - Sylvain [1] http://taoframework.com/ [2] http://glfw.sourceforge.net/ import clr clr.AddReference('Tao.Glfw') clr.AddReference('Tao.OpenGl') from Tao.Glfw import Glfw from Tao.OpenGl import Gl, Glu def run(): Glfw.glfwInit() if not Glfw.glfwOpenWindow(640, 480, 0, 0, 0, 0, 0, 0, Glfw.GLFW_WINDOW): Glfw.glfwTerminate() return 2 Glfw.glfwEnable(Glfw.GLFW_STICKY_KEYS) Glfw.glfwSwapInterval(0) running = True frame_count = 0 start_time = Glfw.glfwGetTime() while running: current_time = Glfw.glfwGetTime() coordinates = Glfw.glfwGetMousePos() #Calculate and display FPS (frames per second) if (current_time - start_time) > 1 or frame_count == 0: frame_rate = frame_count / (current_time - start_time); Glfw.glfwSetWindowTitle("Spinning Triangle (%d FPS)" % frame_rate) start_time = current_time frame_count = 0 frame_count = frame_count + 1 window_dim = Glfw.glfwGetWindowSize() if window_dim[1] > 0: height = window_dim[1] else: height = 1 # Set viewport Gl.glViewport(0, 0, window_dim[0], height) # Clear color buffer Gl.glClearColor(0, 0, 0, 0) Gl.glClear(Gl.GL_COLOR_BUFFER_BIT) # Select and setup the projection matrix Gl.glMatrixMode(Gl.GL_PROJECTION) Gl.glLoadIdentity() Glu.gluPerspective(65, window_dim[0]/height, 1, 100) # Select and setup the modelview matrix Gl.glMatrixMode(Gl.GL_MODELVIEW) Gl.glLoadIdentity() Glu.gluLookAt(0, 1, 0, 0, 20, 0, 0, 0, 1) # Draw a rotating colorful triangle Gl.glTranslatef(0, 14, 0) Gl.glRotatef(1/3 * float(coordinates[0]) + float(current_time) * 100, 0, 0, 1) Gl.glBegin(Gl.GL_TRIANGLES) Gl.glColor3f(1, 0, 0) Gl.glVertex3f(-5, 0, -4) Gl.glColor3f(0, 1, 0) Gl.glVertex3f(5, 0, -4) Gl.glColor3f(0, 0, 1) Gl.glVertex3f(0, 0, 6) Gl.glEnd(); Glfw.glfwSwapBuffers() running = ((Glfw.glfwGetKey(Glfw.GLFW_KEY_ESC) == Glfw.GLFW_RELEASE) and Glfw.glfwGetWindowParam(Glfw.GLFW_OPENED) == Gl.GL_TRUE) Glfw.glfwTerminate() if __name__ == '__main__': run() jane janet a ?crit : > > Hi all, > > I need help again. > I don't know how to use OpenGL in IronPython. > I want to draw the line in IronPython application. > Please teach me clearly. > > All the best, > Jane > > *Jane* > > > ------------------------------------------------------------------------ > Connect and share in new ways with Windows Live. Get it now! > > > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From anakinnani at hotmail.com Sun Feb 17 15:24:13 2008 From: anakinnani at hotmail.com (jane janet) Date: Sun, 17 Feb 2008 14:24:13 +0000 Subject: [IronPython] How to use Tao.Glfw or Tao.OpenGL Zooming windows Message-ID: Hi all, Me again. I wanna know how to zoom my application windows using Tao framework. I have no experience in this stuff. Please tell me clearly. All the best, Jane Jane _________________________________________________________________ Helping your favorite cause is as easy as instant messaging.?You IM, we give. http://im.live.com/Messenger/IM/Home/?source=text_hotmail_join -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at voidspace.org.uk Sun Feb 17 15:26:45 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Sun, 17 Feb 2008 14:26:45 +0000 Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 Message-ID: <47B84425.9090804@voidspace.org.uk> IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.1433 Copyright (c) Microsoft Corporation. All rights reserved. >>> import urllib >>> urllib.urlretrieve('http://python-twitter.googlecode.com/files/python-twitte r-0.5.tar.gz', 'python-twitter.tar.gz') Traceback (most recent call last): File System, line unknown, in Read File System, line unknown, in Receive File System, line unknown, in Receive File c:\Python24\Lib\urllib.py, line 248, in retrieve File System, line unknown, in Read File , line unknown, in ##269 File c:\Python24\Lib\urllib.py, line 89, in urlretrieve IOError: Unable to read data from the transport connection: Cannot access a disp osed object. Object name: 'System.Net.Sockets.Socket'.. Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib >>> urllib.urlretrieve('http://python-twitter.googlecode.com/files/python-twitte r-0.5.tar.gz', 'python-twitter.tar.gz') ('python-twitter.tar.gz', ) >>> From sh at defuze.org Sun Feb 17 16:27:54 2008 From: sh at defuze.org (Sylvain Hellegouarch) Date: Sun, 17 Feb 2008 15:27:54 +0000 Subject: [IronPython] How to use Tao.Glfw or Tao.OpenGL Zooming windows In-Reply-To: References: Message-ID: <47B8527A.4020006@defuze.org> Hi Jane, I'd say that you'll have to go through the Tao documentation [1] and get a good OpenGL tutorial [2]. Note that the Tao distribution contains the NeHe tutorial ported to C#. I don't remember much of my OpenGL years but I think zoom doesn't exist per se, instead you change the view matrix. Have a look at [3]. - Sylvain [1] http://taoframework.com/project [2] http://nehe.gamedev.net/ [3] http://www.opengl.org/resources/faq/technical/viewing.htm jane janet a ?crit : > > Hi all, > Me again. > I wanna know how to zoom my application windows using Tao framework. > I have no experience in this stuff. > Please tell me clearly. > > All the best, > > Jane > > *Jane* > > > ------------------------------------------------------------------------ > Helping your favorite cause is as easy as instant messaging. You IM, > we give. Learn more. > > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From anakinnani at hotmail.com Sun Feb 17 15:38:42 2008 From: anakinnani at hotmail.com (jane janet) Date: Sun, 17 Feb 2008 14:38:42 +0000 Subject: [IronPython] How to use Tao.Glfw or Tao.OpenGL Zooming windows Message-ID: I forgot to tell you something. My application window is 2 dimension. I wanna zoom 2D windows. Best regards, Jane Jane _________________________________________________________________ Shed those extra pounds with MSN and The Biggest Loser! http://biggestloser.msn.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From anakinnani at hotmail.com Sun Feb 17 15:42:52 2008 From: anakinnani at hotmail.com (jane janet) Date: Sun, 17 Feb 2008 14:42:52 +0000 Subject: [IronPython] How to use Tao.Glfw or Tao.OpenGL Zooming windows In-Reply-To: <47B8527A.4020006@defuze.org> References: <47B8527A.4020006@defuze.org> Message-ID: Hello Sylvain, Thank you for your help. I will try your suggestions. I appreciate that. Warm regards, Jane Jane > Date: Sun, 17 Feb 2008 15:27:54 +0000 > From: sh at defuze.org > To: users at lists.ironpython.com > Subject: Re: [IronPython] How to use Tao.Glfw or Tao.OpenGL Zooming windows > > Hi Jane, > > I'd say that you'll have to go through the Tao documentation [1] and get > a good OpenGL tutorial [2]. Note that the Tao distribution contains the > NeHe tutorial ported to C#. > > I don't remember much of my OpenGL years but I think zoom doesn't exist > per se, instead you change the view matrix. Have a look at [3]. > > - Sylvain > > [1] http://taoframework.com/project > [2] http://nehe.gamedev.net/ > [3] http://www.opengl.org/resources/faq/technical/viewing.htm > > jane janet a ?crit : > > > > Hi all, > > Me again. > > I wanna know how to zoom my application windows using Tao framework. > > I have no experience in this stuff. > > Please tell me clearly. > > > > All the best, > > > > Jane > > > > *Jane* > > > > > > ------------------------------------------------------------------------ > > Helping your favorite cause is as easy as instant messaging. You IM, > > we give. Learn more. > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _________________________________________________________________ Climb to the top of the charts!?Play the word scramble challenge with star power. http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_jan -------------- next part -------------- An HTML attachment was scrubbed... URL: From sh at defuze.org Sun Feb 17 16:42:22 2008 From: sh at defuze.org (Sylvain Hellegouarch) Date: Sun, 17 Feb 2008 15:42:22 +0000 Subject: [IronPython] How to use Tao.Glfw or Tao.OpenGL Zooming windows In-Reply-To: References: Message-ID: <47B855DE.8080108@defuze.org> Jane, If you're only interested in 2D, you might want to use TaoSDL rather than TaoOpenGL+TaoGLFW. SDL is a pretty cool graphics library that runs on practically anything that exists. It might be easier than OpenGL but will only make sense in 2D context. For instance look at SdlGfx.zoomSurface from [1]. - Sylvain [1] http://docs.taoframework.com/Tao.Sdl/ jane janet a ?crit : > I forgot to tell you something. > My application window is 2 dimension. > I wanna zoom 2D windows. > > Best regards, > Jane > > > *Jane* > > > ------------------------------------------------------------------------ > Shed those extra pounds with MSN and The Biggest Loser! Learn more. > > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From sh at defuze.org Sun Feb 17 19:32:38 2008 From: sh at defuze.org (Sylvain Hellegouarch) Date: Sun, 17 Feb 2008 18:32:38 +0000 Subject: [IronPython] How to use Tao.Glfw or Tao.OpenGL Zooming windows In-Reply-To: <47B855DE.8080108@defuze.org> References: <47B855DE.8080108@defuze.org> Message-ID: <47B87DC6.20706@defuze.org> FYI, I took a couple of hours to write an example using TaoSDL on the IronPython cookbook [1]. I wanted to notice that accessing attributes is not very smooth and I assume it's due to the fac that TaoSDL structures are all unmanaged. Not very foxy :) - Sylvain [1] http://www.ironpython.info/index.php/SDL_Zoom Sylvain Hellegouarch a ?crit : > Jane, > > If you're only interested in 2D, you might want to use TaoSDL rather > than TaoOpenGL+TaoGLFW. SDL is a pretty cool graphics library that runs > on practically anything that exists. > > It might be easier than OpenGL but will only make sense in 2D context. > > For instance look at SdlGfx.zoomSurface from [1]. > > - Sylvain > > [1] http://docs.taoframework.com/Tao.Sdl/ > > jane janet a ?crit : > >> I forgot to tell you something. >> My application window is 2 dimension. >> I wanna zoom 2D windows. >> >> Best regards, >> Jane >> >> >> *Jane* >> >> >> ------------------------------------------------------------------------ >> Shed those extra pounds with MSN and The Biggest Loser! Learn more. >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From dinov at exchange.microsoft.com Mon Feb 18 19:54:01 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 18 Feb 2008 10:54:01 -0800 Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 In-Reply-To: <47B84425.9090804@voidspace.org.uk> References: <47B84425.9090804@voidspace.org.uk> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4D2730D@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Certainly sounds like a bug - did this work before alpha 8? -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: Sunday, February 17, 2008 6:27 AM To: Discussion of IronPython Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.1433 Copyright (c) Microsoft Corporation. All rights reserved. >>> import urllib >>> urllib.urlretrieve('http://python-twitter.googlecode.com/files/python-twitte r-0.5.tar.gz', 'python-twitter.tar.gz') Traceback (most recent call last): File System, line unknown, in Read File System, line unknown, in Receive File System, line unknown, in Receive File c:\Python24\Lib\urllib.py, line 248, in retrieve File System, line unknown, in Read File , line unknown, in ##269 File c:\Python24\Lib\urllib.py, line 89, in urlretrieve IOError: Unable to read data from the transport connection: Cannot access a disp osed object. Object name: 'System.Net.Sockets.Socket'.. Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib >>> urllib.urlretrieve('http://python-twitter.googlecode.com/files/python-twitte r-0.5.tar.gz', 'python-twitter.tar.gz') ('python-twitter.tar.gz', ) >>> _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From fuzzyman at voidspace.org.uk Mon Feb 18 19:58:21 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Mon, 18 Feb 2008 18:58:21 +0000 Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF4D2730D@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <47B84425.9090804@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D2730D@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <47B9D54D.1020600@voidspace.org.uk> Dino Viehland wrote: > Certainly sounds like a bug - did this work before alpha 8? > I don't *think* it has ever worked - but problems with urllib/urllib2 seem to be one of the most common frustrations with IronPython for people coming from Python so I thought it was worth flagging. Michael > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord > Sent: Sunday, February 17, 2008 6:27 AM > To: Discussion of IronPython > Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 > > IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.1433 > Copyright (c) Microsoft Corporation. All rights reserved. > >>> import urllib > >>> > urllib.urlretrieve('http://python-twitter.googlecode.com/files/python-twitte > r-0.5.tar.gz', 'python-twitter.tar.gz') > Traceback (most recent call last): > File System, line unknown, in Read > File System, line unknown, in Receive > File System, line unknown, in Receive > File c:\Python24\Lib\urllib.py, line 248, in retrieve > File System, line unknown, in Read > File , line unknown, in ##269 > File c:\Python24\Lib\urllib.py, line 89, in urlretrieve > IOError: Unable to read data from the transport connection: Cannot > access a disp > osed object. > Object name: 'System.Net.Sockets.Socket'.. > > > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import urllib > >>> > urllib.urlretrieve('http://python-twitter.googlecode.com/files/python-twitte > r-0.5.tar.gz', 'python-twitter.tar.gz') > ('python-twitter.tar.gz', ) > >>> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From curt at hagenlocher.org Mon Feb 18 23:38:04 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Mon, 18 Feb 2008 14:38:04 -0800 Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF4D2730D@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <47B84425.9090804@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D2730D@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: This is in Codeplex as work item 10518 http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=10518 The item was marked as a duplicate of 10825, which has been marked as resolved in 1.1.1. However, I am able to reproduce the problem with 1.1, 1.1.1 and alpha 8. On Feb 18, 2008 10:54 AM, Dino Viehland wrote: > Certainly sounds like a bug - did this work before alpha 8? > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto: > users-bounces at lists.ironpython.com] On Behalf Of Michael Foord > Sent: Sunday, February 17, 2008 6:27 AM > To: Discussion of IronPython > Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 > > IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.1433 > Copyright (c) Microsoft Corporation. All rights reserved. > >>> import urllib > >>> > urllib.urlretrieve(' > http://python-twitter.googlecode.com/files/python-twitte > r-0.5.tar.gz', 'python-twitter.tar.gz') > Traceback (most recent call last): > File System, line unknown, in Read > File System, line unknown, in Receive > File System, line unknown, in Receive > File c:\Python24\Lib\urllib.py, line 248, in retrieve > File System, line unknown, in Read > File , line unknown, in ##269 > File c:\Python24\Lib\urllib.py, line 89, in urlretrieve > IOError: Unable to read data from the transport connection: Cannot > access a disp > osed object. > Object name: 'System.Net.Sockets.Socket'.. > > > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import urllib > >>> > urllib.urlretrieve(' > http://python-twitter.googlecode.com/files/python-twitte > r-0.5.tar.gz', 'python-twitter.tar.gz') > ('python-twitter.tar.gz', ) > >>> > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From curt at hagenlocher.org Tue Feb 19 00:00:53 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Mon, 18 Feb 2008 15:00:53 -0800 Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 In-Reply-To: References: <47B84425.9090804@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D2730D@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: I should amend this to say that I can *inconsistently* reproduce it. The URL in the original sample always fails with that error, but http://www.microsoft.com has been succeeding for me more often than not. On Feb 18, 2008 2:38 PM, Curt Hagenlocher wrote: > This is in Codeplex as work item 10518 > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=10518 > > The item was marked as a duplicate of 10825, which has been marked as > resolved in 1.1.1. However, I am able to reproduce the problem with 1.1, > 1.1.1 and alpha 8. > > On Feb 18, 2008 10:54 AM, Dino Viehland > wrote: > > > Certainly sounds like a bug - did this work before alpha 8? > > > > -----Original Message----- > > From: users-bounces at lists.ironpython.com [mailto: > > users-bounces at lists.ironpython.com] On Behalf Of Michael Foord > > Sent: Sunday, February 17, 2008 6:27 AM > > To: Discussion of IronPython > > Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 > > > > IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.1433 > > Copyright (c) Microsoft Corporation. All rights reserved. > > >>> import urllib > > >>> > > urllib.urlretrieve(' > > http://python-twitter.googlecode.com/files/python-twitte > > r-0.5.tar.gz', 'python-twitter.tar.gz') > > Traceback (most recent call last): > > File System, line unknown, in Read > > File System, line unknown, in Receive > > File System, line unknown, in Receive > > File c:\Python24\Lib\urllib.py, line 248, in retrieve > > File System, line unknown, in Read > > File , line unknown, in ##269 > > File c:\Python24\Lib\urllib.py, line 89, in urlretrieve > > IOError: Unable to read data from the transport connection: Cannot > > access a disp > > osed object. > > Object name: 'System.Net.Sockets.Socket'.. > > > > > > > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit > > (Intel)] on > > win32 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> import urllib > > >>> > > urllib.urlretrieve(' > > http://python-twitter.googlecode.com/files/python-twitte > > r-0.5.tar.gz', 'python-twitter.tar.gz') > > ('python-twitter.tar.gz', ) > > >>> > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at voidspace.org.uk Tue Feb 19 00:11:24 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Mon, 18 Feb 2008 23:11:24 +0000 Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 In-Reply-To: References: <47B84425.9090804@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D2730D@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <6f4025010802181511t551732ebme21807486e8c055d@mail.gmail.com> On 18/02/2008, Curt Hagenlocher wrote: > > I should amend this to say that I can *inconsistently* reproduce it. The > URL in the original sample always fails with that error, but > http://www.microsoft.com has been succeeding for me more often than not. Hmmm... could be a difference in the default socket timeout, or when the socket object is created (?). Whatever the cause I think the bug should be reopened. Michael On Feb 18, 2008 2:38 PM, Curt Hagenlocher wrote: > > > This is in Codeplex as work item 10518 > > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=10518 > > > > The item was marked as a duplicate of 10825, which has been marked as > > resolved in 1.1.1. However, I am able to reproduce the problem with 1.1, > > 1.1.1 and alpha 8. > > > > On Feb 18, 2008 10:54 AM, Dino Viehland > > wrote: > > > > > Certainly sounds like a bug - did this work before alpha 8? > > > > > > -----Original Message----- > > > From: users-bounces at lists.ironpython.com [mailto: > > > users-bounces at lists.ironpython.com] On Behalf Of Michael Foord > > > Sent: Sunday, February 17, 2008 6:27 AM > > > To: Discussion of IronPython > > > Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 > > > > > > IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.1433 > > > Copyright (c) Microsoft Corporation. All rights reserved. > > > >>> import urllib > > > >>> > > > urllib.urlretrieve(' > > > http://python-twitter.googlecode.com/files/python-twitte > > > r-0.5.tar.gz', > > > 'python-twitter.tar.gz') > > > Traceback (most recent call last): > > > File System, line unknown, in Read > > > File System, line unknown, in Receive > > > File System, line unknown, in Receive > > > File c:\Python24\Lib\urllib.py, line 248, in retrieve > > > File System, line unknown, in Read > > > File , line unknown, in ##269 > > > File c:\Python24\Lib\urllib.py, line 89, in urlretrieve > > > IOError: Unable to read data from the transport connection: Cannot > > > access a disp > > > osed object. > > > Object name: 'System.Net.Sockets.Socket'.. > > > > > > > > > > > > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit > > > (Intel)] on > > > win32 > > > Type "help", "copyright", "credits" or "license" for more information. > > > >>> import urllib > > > >>> > > > urllib.urlretrieve(' > > > http://python-twitter.googlecode.com/files/python-twitte > > > r-0.5.tar.gz', > > > 'python-twitter.tar.gz') > > > ('python-twitter.tar.gz', > > 0x01864E40>) > > > >>> > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -- http://www.manning.com/foord http://www.voidspace.org.uk http://www.ironpython.info -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Tue Feb 19 00:20:07 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 18 Feb 2008 15:20:07 -0800 Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 In-Reply-To: <6f4025010802181511t551732ebme21807486e8c055d@mail.gmail.com> References: <47B84425.9090804@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D2730D@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <6f4025010802181511t551732ebme21807486e8c055d@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4D27420@DF-GRTDANE-MSG.exchange.corp.microsoft.com> I'll re-activate it (I'm currently getting a CodePlex is undergoing some upgrade message, so it may take a little while). I agree, we should definitely make sure this is working. I thought urllib was working better in 2.0, and there are some improvements that should make 1.1.1 better, but it's not good enough yet. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: Monday, February 18, 2008 3:11 PM To: Discussion of IronPython Subject: Re: [IronPython] urllib.urlretrieve with IronPython 2a8 On 18/02/2008, Curt Hagenlocher > wrote: I should amend this to say that I can *inconsistently* reproduce it. The URL in the original sample always fails with that error, but http://www.microsoft.com has been succeeding for me more often than not. Hmmm... could be a difference in the default socket timeout, or when the socket object is created (?). Whatever the cause I think the bug should be reopened. Michael On Feb 18, 2008 2:38 PM, Curt Hagenlocher > wrote: This is in Codeplex as work item 10518 http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=10518 The item was marked as a duplicate of 10825, which has been marked as resolved in 1.1.1. However, I am able to reproduce the problem with 1.1, 1.1.1 and alpha 8. On Feb 18, 2008 10:54 AM, Dino Viehland > wrote: Certainly sounds like a bug - did this work before alpha 8? -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: Sunday, February 17, 2008 6:27 AM To: Discussion of IronPython Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.1433 Copyright (c) Microsoft Corporation. All rights reserved. >>> import urllib >>> urllib.urlretrieve('http://python-twitter.googlecode.com/files/python-twitte r-0.5.tar.gz', 'python-twitter.tar.gz') Traceback (most recent call last): File System, line unknown, in Read File System, line unknown, in Receive File System, line unknown, in Receive File c:\Python24\Lib\urllib.py, line 248, in retrieve File System, line unknown, in Read File , line unknown, in ##269 File c:\Python24\Lib\urllib.py, line 89, in urlretrieve IOError: Unable to read data from the transport connection: Cannot access a disp osed object. Object name: 'System.Net.Sockets.Socket'.. Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import urllib >>> urllib.urlretrieve('http://python-twitter.googlecode.com/files/python-twitte r-0.5.tar.gz', 'python-twitter.tar.gz') ('python-twitter.tar.gz', ) >>> _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com -- http://www.manning.com/foord http://www.voidspace.org.uk http://www.ironpython.info -------------- next part -------------- An HTML attachment was scrubbed... URL: From curt at hagenlocher.org Tue Feb 19 00:34:59 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Mon, 18 Feb 2008 15:34:59 -0800 Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 In-Reply-To: <6f4025010802181511t551732ebme21807486e8c055d@mail.gmail.com> References: <47B84425.9090804@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D2730D@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <6f4025010802181511t551732ebme21807486e8c055d@mail.gmail.com> Message-ID: On Feb 18, 2008 3:11 PM, Michael Foord wrote: > > On 18/02/2008, Curt Hagenlocher wrote: >> I should amend this to say that I can *inconsistently* reproduce it. The URL >> in the original sample always fails with that error, but http://www.microsoft.com >> has been succeeding for me more often than not. > > Hmmm... could be a difference in the default socket timeout, or when the socket > object is created (?). Whatever the cause I think the bug should be reopened. One difference between the two is that www.microsoft.com actually has an HTTP redirect involved, while the failing version does not. Here's a simpler way to reproduce the problem: import httplib h = httplib.HTTP('www.google.com') h.putrequest('GET', '/') h.endheaders() a, b, c = h.getreply() fp = h.getfile() fp.read(1024*8) This fails with the same "disposed object" error, but replacing google with microsoft makes it work correctly. Any "business/political" implications thereof are left as an exercise to the reader ;). -- Curt Hagenlocher curt at hagenlocher.org From curt at hagenlocher.org Tue Feb 19 01:12:04 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Mon, 18 Feb 2008 16:12:04 -0800 Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 In-Reply-To: References: <47B84425.9090804@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D2730D@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <6f4025010802181511t551732ebme21807486e8c055d@mail.gmail.com> Message-ID: On Feb 18, 2008 3:34 PM, Curt Hagenlocher wrote: > > Here's a simpler way to reproduce the problem: > > import httplib > h = httplib.HTTP('www.google.com') > h.putrequest('GET', '/') > h.endheaders() > a, b, c = h.getreply() > fp = h.getfile() > fp.read(1024*8) Turning debugging on at a Python level reveals a crucial difference between the sites. Sites for which the HTTP header contains "Connection: close" fail, while sites for which the HTTP header contains "Connection: keep-alive" stay open. Is it possible that CPython's socket.close method won't actually close the socket while there's still a makefile'd file attacked to the underlying OS socket? And that IronPython's will? Because that's the only explanation I can come up with. -- Curt Hagenlocher curt at hagenlocher.org From curt at hagenlocher.org Tue Feb 19 01:18:48 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Mon, 18 Feb 2008 16:18:48 -0800 Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 In-Reply-To: References: <47B84425.9090804@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D2730D@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <6f4025010802181511t551732ebme21807486e8c055d@mail.gmail.com> Message-ID: On Feb 18, 2008 4:12 PM, Curt Hagenlocher wrote: > > Is it possible that CPython's socket.close method won't actually close > the socket while there's still a makefile'd file attacked to the > underlying OS socket? And that IronPython's will? Because that's the > only explanation I can come up with. It is and it will. CPython basically dups the socket handle when you call makefile, while IronPython does not. That's the cause of this bug. By the way, the docstring for the IronPython socket class claims that makefile isn't implemented. This is apparently only half-true. :P -- Curt Hagenlocher curt at hagenlocher.org From dinov at exchange.microsoft.com Tue Feb 19 05:19:38 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 18 Feb 2008 20:19:38 -0800 Subject: [IronPython] urllib.urlretrieve with IronPython 2a8 In-Reply-To: References: <47B84425.9090804@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D2730D@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <6f4025010802181511t551732ebme21807486e8c055d@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4D274D2@DF-GRTDANE-MSG.exchange.corp.microsoft.com> This is a great analysis - based upon this I think it'll be pretty easy to fix this. I'll take a look at it tomorrow and respond back. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Monday, February 18, 2008 4:19 PM To: Discussion of IronPython Subject: Re: [IronPython] urllib.urlretrieve with IronPython 2a8 On Feb 18, 2008 4:12 PM, Curt Hagenlocher wrote: > > Is it possible that CPython's socket.close method won't actually close > the socket while there's still a makefile'd file attacked to the > underlying OS socket? And that IronPython's will? Because that's the > only explanation I can come up with. It is and it will. CPython basically dups the socket handle when you call makefile, while IronPython does not. That's the cause of this bug. By the way, the docstring for the IronPython socket class claims that makefile isn't implemented. This is apparently only half-true. :P -- Curt Hagenlocher curt at hagenlocher.org _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From michael.foord at resolversystems.com Tue Feb 19 17:31:23 2008 From: michael.foord at resolversystems.com (Michael Foord) Date: Tue, 19 Feb 2008 16:31:23 +0000 Subject: [IronPython] Overriding __iter__ in dict subclass Message-ID: <47BB045B.2070307@resolversystems.com> Bug in IronPython 1 and 2. IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.832 Copyright (c) Microsoft Corporation. All rights reserved. >>> class X(dict): ... __iter__ = lambda s: s.itervalues() ... >>> a = X([(1, 'a'), (2, 'b'), (3, 'c')]) >>> for e in a: ... print e ... 1 2 3 >>> IronPython 1.1 >>> class X(dict): ... __iter__ = lambda s: s.itervalues() ... >>> a = X([(1, 'a'), (2, 'b'), (3, 'c')]) >>> for e in a: ... print e ... 1 2 3 >>> CPython 2.4 Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class X(dict): ... __iter__ = lambda s: s.itervalues() ... >>> a = X([(1, 'a'), (2, 'b'), (3, 'c')]) >>> >>> for e in a: ... print e ... a b c >>> -- Michael Foord Senior Software Engineer, Resolver Systems Ltd. michael.foord at resolversystems.com +44 (0) 20 7253 6372 We're hiring! http://www.resolversystems.com/jobs/ 17a Clerkenwell Road, London EC1M 5RD, UK VAT No.: GB 893 5643 79 Registered in England and Wales as company number 5467329. Registered address: 843 Finchley Road, London NW11 8NA, UK From dinov at exchange.microsoft.com Wed Feb 20 00:38:12 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Tue, 19 Feb 2008 15:38:12 -0800 Subject: [IronPython] Overriding __iter__ in dict subclass In-Reply-To: <47BB045B.2070307@resolversystems.com> References: <47BB045B.2070307@resolversystems.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4D276B4@DF-GRTDANE-MSG.exchange.corp.microsoft.com> This one's interesting. I've got a fix for this for 2.0 on my machine - I've been looking at some other tweaks to dictionaries so we can cleanup our type system (funny how those two are related) and this fits in nicely with that. So it should be in the next release. Thanks for the report! -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: Tuesday, February 19, 2008 8:31 AM To: Discussion of IronPython Subject: [IronPython] Overriding __iter__ in dict subclass Bug in IronPython 1 and 2. IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.832 Copyright (c) Microsoft Corporation. All rights reserved. >>> class X(dict): ... __iter__ = lambda s: s.itervalues() ... >>> a = X([(1, 'a'), (2, 'b'), (3, 'c')]) >>> for e in a: ... print e ... 1 2 3 >>> IronPython 1.1 >>> class X(dict): ... __iter__ = lambda s: s.itervalues() ... >>> a = X([(1, 'a'), (2, 'b'), (3, 'c')]) >>> for e in a: ... print e ... 1 2 3 >>> CPython 2.4 Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class X(dict): ... __iter__ = lambda s: s.itervalues() ... >>> a = X([(1, 'a'), (2, 'b'), (3, 'c')]) >>> >>> for e in a: ... print e ... a b c >>> -- Michael Foord Senior Software Engineer, Resolver Systems Ltd. michael.foord at resolversystems.com +44 (0) 20 7253 6372 We're hiring! http://www.resolversystems.com/jobs/ 17a Clerkenwell Road, London EC1M 5RD, UK VAT No.: GB 893 5643 79 Registered in England and Wales as company number 5467329. Registered address: 843 Finchley Road, London NW11 8NA, UK _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From birsch at gmail.com Wed Feb 20 12:58:33 2008 From: birsch at gmail.com (Birsch) Date: Wed, 20 Feb 2008 13:58:33 +0200 Subject: [IronPython] Slow Performance of CPython libs? Message-ID: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> Hi - We've been using IronPython successfully to allow extensibility of our application. Overall we are happy with the performance, with the exception of BeautifulSoup which seems to run very slowly: x5 or more time to execute compared to CPython. Most of the time seems to be spent during __init__() of BS, where the markup is parsed. We suspect this has to do with the fact that our CPython env is executing .pyc files and can precompile its libs, while the IronPython environment compiles each iteration. We couldn't find a way to pre-compile the libs and then introduce them into the code, but in any case this will result in a large management overhead since the amount of CPython libs we expose to our users contains 100's of modules. Any ideas on how to optimize? Thanks, -Birsch Note: we're using FePy/IPCE libs with regular IP v1.1.1 runtime DLLs (this was done to overcome library incompatibilities and network errors). However, the relevant slow .py code (mainly SGMLParser and BeautifulSoup) is the same. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at voidspace.org.uk Wed Feb 20 14:19:46 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Wed, 20 Feb 2008 13:19:46 +0000 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> Message-ID: <47BC28F2.1020009@voidspace.org.uk> Birsch wrote: > Hi - We've been using IronPython successfully to allow extensibility > of our application. > > Overall we are happy with the performance, with the exception of > BeautifulSoup which seems to run very slowly: x5 or more time to > execute compared to CPython. > > Most of the time seems to be spent during __init__() of BS, where the > markup is parsed. > > We suspect this has to do with the fact that our CPython env is > executing .pyc files and can precompile its libs, while the IronPython > environment compiles each iteration. We couldn't find a way to > pre-compile the libs and then introduce them into the code, but in any > case this will result in a large management overhead since the amount > of CPython libs we expose to our users contains 100's of modules. > > Any ideas on how to optimize? I think it is worth doing real profiling to find out where the time is being spent during parsing. If it is spending most of the time in '__init__' then the time is probably not spent in importing - so compilation isn't relevant and it is a runtime performance issue. (Importing is much slower with IronPython and at Resolver Systems we do use precompiled binaries - but strangely enough it doesn't provide much of a performance gain.) Michael http://www.manning.com/foord > > Thanks, > -Birsch > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 runtime DLLs > (this was done to overcome library incompatibilities and network > errors). However, the relevant slow .py code (mainly SGMLParser and > BeautifulSoup) is the same. > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From dinov at exchange.microsoft.com Wed Feb 20 17:57:27 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 20 Feb 2008 08:57:27 -0800 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <47BC28F2.1020009@voidspace.org.uk> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> We've actually had this issue reported once before a long time ago - it's a very low CodePlex ID - http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 We haven't had a chance to investigate the end-to-end scenario. If someone could come up with a smaller simpler repro that'd be great. Otherwise we haven't forgotten about it we've just had more immediately pressing issues to work on :(. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: Wednesday, February 20, 2008 5:20 AM To: Discussion of IronPython Subject: Re: [IronPython] Slow Performance of CPython libs? Birsch wrote: > Hi - We've been using IronPython successfully to allow extensibility > of our application. > > Overall we are happy with the performance, with the exception of > BeautifulSoup which seems to run very slowly: x5 or more time to > execute compared to CPython. > > Most of the time seems to be spent during __init__() of BS, where the > markup is parsed. > > We suspect this has to do with the fact that our CPython env is > executing .pyc files and can precompile its libs, while the IronPython > environment compiles each iteration. We couldn't find a way to > pre-compile the libs and then introduce them into the code, but in any > case this will result in a large management overhead since the amount > of CPython libs we expose to our users contains 100's of modules. > > Any ideas on how to optimize? I think it is worth doing real profiling to find out where the time is being spent during parsing. If it is spending most of the time in '__init__' then the time is probably not spent in importing - so compilation isn't relevant and it is a runtime performance issue. (Importing is much slower with IronPython and at Resolver Systems we do use precompiled binaries - but strangely enough it doesn't provide much of a performance gain.) Michael http://www.manning.com/foord > > Thanks, > -Birsch > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 runtime DLLs > (this was done to overcome library incompatibilities and network > errors). However, the relevant slow .py code (mainly SGMLParser and > BeautifulSoup) is the same. > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From dinov at exchange.microsoft.com Wed Feb 20 20:56:48 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 20 Feb 2008 11:56:48 -0800 Subject: [IronPython] Our team is growing! Message-ID: <7AD436E4270DD54A94238001769C2227011CF4D27873@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Hi everyone! I just wanted to let you know that our team is growing and we're looking to hire some new people to work on IronPython, IronRuby, and F#. We have 6 new positions we're trying to fill. IronPython developer position: http://members.microsoft.com/careers/search/details.aspx?JobID=8BEEE2C2-A95D-41C6-9075-CF6347EE07F1 IronRuby developer position: http://members.microsoft.com/careers/search/details.aspx?JobID=7C2E33E8-5A9C-44F3-A1CE-DA2D66DC3C8B IronRuby QA position: http://members.microsoft.com/careers/search/details.aspx?JobID=FF36A073-D1E8-49A9-B942-AFA4AB2B437E We also have positions open for doing F# development, F# QA as well as an IronPython Program Manager position - unfortunately there's no website entry for those just yet. Here's the IronPython PM description, unfortunately I have no descriptions for the F# jobs right now. The Visual Studio languages team is looking for a Senior Program Manager (Sr. PM) to own our IronPython implementation on www.codeplex.com/ironpython. IronPython is an exciting new open source implementation of the Python programming language running on .NET. It was a 2007 Jolt award finalist http://www.joltawards.com/2007/. It supports an interactive console with fully dynamic compilation. It is well integrated with the rest of the .NET Framework and makes all .NET libraries easily available to Python programmers, while maintaining full compatibility with the Python language. The Sr. PM would be responsible for the vision, planning, strategy and execution of our project. You will work closely with the architect, developers and testers and the community to ensure the right product is getting built. In addition you will be our primary customer voice, evangelist/public speaker for IronPython in addition to being the liaison for rest of the languages team, marketing, legal and other internal and external partners. Requirements for this position include a bachelors degree in a technical field such as computer science or electrical engineering (Masters preferred), deep experience in using Python and several dynamic languages is required (and having implemented one is preferred). For the development positions you can contact sborde at microsoft.com For the test positions you can contact yalvi at microsoft.com For the PM position you can contact maheshp at microsoft.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From daftspaniel at gmail.com Wed Feb 20 22:21:36 2008 From: daftspaniel at gmail.com (Davy Mitchell) Date: Wed, 20 Feb 2008 21:21:36 +0000 Subject: [IronPython] Bug Query - dict(...) broken on new style class dictionaries Message-ID: <20253b0c0802201321o4fb9f89cq5964ca268f4825bd@mail.gmail.com> Hi Dino, Will this bug make it to the next release? http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=14501 Thanks, Davy -- Davy Mitchell Blog - http://www.latedecember.co.uk/sites/personal/davy/ Twitter - http://twitter.com/daftspaniel Skype - daftspaniel needgod.com From dinov at exchange.microsoft.com Wed Feb 20 22:38:09 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 20 Feb 2008 13:38:09 -0800 Subject: [IronPython] Bug Query - dict(...) broken on new style class dictionaries In-Reply-To: <20253b0c0802201321o4fb9f89cq5964ca268f4825bd@mail.gmail.com> References: <20253b0c0802201321o4fb9f89cq5964ca268f4825bd@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4D278D6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Sure, I can fix that one at the same time I'm doing the other dictionary stuff. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Davy Mitchell Sent: Wednesday, February 20, 2008 1:22 PM To: Discussion of IronPython Subject: [IronPython] Bug Query - dict(...) broken on new style class dictionaries Hi Dino, Will this bug make it to the next release? http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=14501 Thanks, Davy -- Davy Mitchell Blog - http://www.latedecember.co.uk/sites/personal/davy/ Twitter - http://twitter.com/daftspaniel Skype - daftspaniel needgod.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From daftspaniel at gmail.com Wed Feb 20 23:22:20 2008 From: daftspaniel at gmail.com (Davy Mitchell) Date: Wed, 20 Feb 2008 22:22:20 +0000 Subject: [IronPython] Bug Query - dict(...) broken on new style class dictionaries In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF4D278D6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <20253b0c0802201321o4fb9f89cq5964ca268f4825bd@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4D278D6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <20253b0c0802201422n626d9448s7ed106bc70c015ca@mail.gmail.com> Thanks Dino! :-) On Wed, Feb 20, 2008 at 9:38 PM, Dino Viehland wrote: > Sure, I can fix that one at the same time I'm doing the other dictionary stuff. > > > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Davy Mitchell > Sent: Wednesday, February 20, 2008 1:22 PM > To: Discussion of IronPython > Subject: [IronPython] Bug Query - dict(...) broken on new style class dictionaries > > Hi Dino, > > Will this bug make it to the next release? > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=14501 > > Thanks, > Davy > > -- > Davy Mitchell > Blog - http://www.latedecember.co.uk/sites/personal/davy/ > Twitter - http://twitter.com/daftspaniel > Skype - daftspaniel needgod.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > -- Davy Mitchell Blog - http://www.latedecember.co.uk/sites/personal/davy/ Twitter - http://twitter.com/daftspaniel Skype - daftspaniel needgod.com From birsch at gmail.com Thu Feb 21 13:35:59 2008 From: birsch at gmail.com (Birsch) Date: Thu, 21 Feb 2008 14:35:59 +0200 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> Thanks Michael and Dino. I'll prof and send update. Got a good profiler recommendation for .Net? Meanwhile I noticed the sample site below causes BeautifulSoup to generate quite a few [python] exceptions during __init__. Does IronPython handle exceptions significantly slower than CPtyhon? Repro code is simple (just build a BeautifulSoup obj with mininova's home page). Here are the .py and .cs I used to time the diffs: *bstest.py:* #Bypass CPython default socket implementation with IPCE/FePy import imp, os, sys sys.modules['socket'] = module = imp.new_module('socket') execfile('socket.py', module.__dict__) from BeautifulSoup import BeautifulSoup from urllib import urlopen import datetime def getContent(url): #Download html data startTime = datetime.datetime.now() print "Getting url", url html = urlopen(url).read() print "Time taken:", datetime.datetime.now() - startTime #Make soup startTime = datetime.datetime.now() print "Making soup..." soup = BeautifulSoup(markup=html) print "Time taken:", datetime.datetime.now() - startTime if __name__ == "__main__": print getContent("www.mininova.org") *C#:* using System; using System.Collections.Generic; using System.Text; using IronPython.Hosting; namespace IronPythonBeautifulSoupTest { public class Program { public static void Main(string[] args) { //Init System.Console.WriteLine("Starting..."); DateTime start = DateTime.Now; PythonEngine engine = new PythonEngine(); //Add paths: //BeautifulSoup.py, socket.py, bstest.py located on exe dir engine.AddToPath(@"."); //CPython Lib (replace with your own) engine.AddToPath(@"D:\Dev\Python\Lib"); //Import and load TimeSpan span = DateTime.Now - start; System.Console.WriteLine("[1] Import: " + span.TotalSeconds); DateTime d = DateTime.Now; engine.ExecuteFile(@"bstest.py"); span = DateTime.Now - d; System.Console.WriteLine("[2] Load: " + span.TotalSeconds); //Execute d = DateTime.Now; engine.Execute("getContent(\"http://www.mininova.org\")"); span = DateTime.Now - d; System.Console.WriteLine("[3] Execute: " + span.TotalSeconds); span = DateTime.Now - start; System.Console.WriteLine("Total: " + span.TotalSeconds); } } } On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland wrote: > We've actually had this issue reported once before a long time ago - it's > a very low CodePlex ID - > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 > > We haven't had a chance to investigate the end-to-end scenario. If > someone could come up with a smaller simpler repro that'd be great. > Otherwise we haven't forgotten about it we've just had more immediately > pressing issues to work on :(. > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto: > users-bounces at lists.ironpython.com] On Behalf Of Michael Foord > Sent: Wednesday, February 20, 2008 5:20 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Slow Performance of CPython libs? > > Birsch wrote: > > Hi - We've been using IronPython successfully to allow extensibility > > of our application. > > > > Overall we are happy with the performance, with the exception of > > BeautifulSoup which seems to run very slowly: x5 or more time to > > execute compared to CPython. > > > > Most of the time seems to be spent during __init__() of BS, where the > > markup is parsed. > > > > We suspect this has to do with the fact that our CPython env is > > executing .pyc files and can precompile its libs, while the IronPython > > environment compiles each iteration. We couldn't find a way to > > pre-compile the libs and then introduce them into the code, but in any > > case this will result in a large management overhead since the amount > > of CPython libs we expose to our users contains 100's of modules. > > > > Any ideas on how to optimize? > > I think it is worth doing real profiling to find out where the time is > being spent during parsing. > > If it is spending most of the time in '__init__' then the time is > probably not spent in importing - so compilation isn't relevant and it > is a runtime performance issue. (Importing is much slower with > IronPython and at Resolver Systems we do use precompiled binaries - but > strangely enough it doesn't provide much of a performance gain.) > > Michael > http://www.manning.com/foord > > > > > Thanks, > > -Birsch > > > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 runtime DLLs > > (this was done to overcome library incompatibilities and network > > errors). However, the relevant slow .py code (mainly SGMLParser and > > BeautifulSoup) is the same. > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From henry at cs.its.ac.id Thu Feb 21 13:35:26 2008 From: henry at cs.its.ac.id (henry at cs.its.ac.id) Date: Thu, 21 Feb 2008 19:35:26 +0700 (WIT) Subject: [IronPython] ironptython xml-rpc how? Message-ID: <1573.10.126.11.236.1203597326.squirrel@webmail.cs.its.ac.id> hello there.... i'me newbie in ironpython. i'm just wondering, is there any way that ironpython dealing with xml-rpc? cause i had imported i tried to import xmlrpclib to ironpython with this code import xmlprclib server = xmlrpclib.Server("localhost:4567") month = server.getMonth(2002, 8) i got this error message : Traceback (most recent call last): File System, line unknown, in Read File System, line unknown, in Receive File System, line unknown, in Receive File , line 0, in ##180 File xmlrpclib, line unknown, in __call__ File D:\Python24\Lib\xmlrpclib.py, line 1096, in __call__ File D:\Python24\Lib\xmlrpclib.py, line 1379, in _ServerProxy__request File D:\Python24\Lib\xmlrpclib.py, line 1147, in request File D:\Python24\Lib\xmlrpclib.py, line 1276, in _parse_response File , line 0, in Read##177 File System, line unknown, in Read IOError: Unable to read data from the transport connection: Cannot access a disp osed object. Object name: 'System.Net.Sockets.Socket'.. the code and the server n client are based on xmlrpc in python based on http://www.ibm.com/developerworks/library/ws-pyth10.html the server run on python 2.4 here is the code : import calendar, SimpleXMLRPCServer #The server object class Calendar: def getMonth(self, year, month): return calendar.month(year, month) def getYear(self, year): return calendar.calendar(year) calendar_object = Calendar() server = SimpleXMLRPCServer.SimpleXMLRPCServer(("10.126.11.212", 4567)) server.register_instance(calendar_object) #Go into the main listener loop print "Listening on port 4567" server.serve_forever() the client run on ironpython 1.1.1 using xmlrpclib on python 2.4.4 import xmlrpclib server = xmlrpclib.ServerProxy("http://localhost:8888") month = server.getMonth(2002, 8) print month can anyone help me with this problem or is there another way to implement xmlprc client in ironpython ? From henry at cs.its.ac.id Thu Feb 21 13:39:24 2008 From: henry at cs.its.ac.id (henry at cs.its.ac.id) Date: Thu, 21 Feb 2008 19:39:24 +0700 (WIT) Subject: [IronPython] xmlrpc in ironpython how? sorry, the first thread there are little mistake in the code.... Message-ID: <1577.10.126.11.236.1203597564.squirrel@webmail.cs.its.ac.id> hello there.... i'me newbie in ironpython. i'm just wondering, is there any way that ironpython dealing with xml-rpc? cause i had imported i tried to import xmlrpclib to ironpython with this code import xmlprclib server = xmlrpclib.Server("localhost:4567") month = server.getMonth(2002, 8) i got this error message : Traceback (most recent call last): File System, line unknown, in Read File System, line unknown, in Receive File System, line unknown, in Receive File , line 0, in ##180 File xmlrpclib, line unknown, in __call__ File D:\Python24\Lib\xmlrpclib.py, line 1096, in __call__ File D:\Python24\Lib\xmlrpclib.py, line 1379, in _ServerProxy__request File D:\Python24\Lib\xmlrpclib.py, line 1147, in request File D:\Python24\Lib\xmlrpclib.py, line 1276, in _parse_response File , line 0, in Read##177 File System, line unknown, in Read IOError: Unable to read data from the transport connection: Cannot access a disp osed object. Object name: 'System.Net.Sockets.Socket'.. the code and the server n client are based on xmlrpc in python based on http://www.ibm.com/developerworks/library/ws-pyth10.html the server run on python 2.4 here is the code : import calendar, SimpleXMLRPCServer #The server object class Calendar: def getMonth(self, year, month): return calendar.month(year, month) def getYear(self, year): return calendar.calendar(year) calendar_object = Calendar() server = SimpleXMLRPCServer.SimpleXMLRPCServer(("10.126.11.212", 4567)) server.register_instance(calendar_object) #Go into the main listener loop print "Listening on port 4567" server.serve_forever() the client run on ironpython 1.1.1 using xmlrpclib on python 2.4.4 import xmlrpclib server = xmlrpclib.ServerProxy("http://10.126.11.212:4567") month = server.getMonth(2002, 8) print month can anyone help me with this problem or is there another way to implement xmlprc client in ironpython ? From daftspaniel at gmail.com Thu Feb 21 13:54:32 2008 From: daftspaniel at gmail.com (Davy Mitchell) Date: Thu, 21 Feb 2008 12:54:32 +0000 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> Message-ID: <20253b0c0802210454g1f63c09ao101cce9a220f0f2b@mail.gmail.com> On Thu, Feb 21, 2008 at 12:35 PM, Birsch wrote: > quite a few [python] exceptions during __init__. Does IronPython handle > exceptions significantly slower than CPtyhon? This has been my experience - I've worked round it by editing modules to avoid nasty bits. Not always practical but saved many seconds in my case. Cheers, Davy -- Davy Mitchell Blog - http://www.latedecember.co.uk/sites/personal/davy/ Twitter - http://twitter.com/daftspaniel Skype - daftspaniel needgod.com From curt at hagenlocher.org Thu Feb 21 14:18:43 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Thu, 21 Feb 2008 05:18:43 -0800 Subject: [IronPython] ironptython xml-rpc how? In-Reply-To: <1573.10.126.11.236.1203597326.squirrel@webmail.cs.its.ac.id> References: <1573.10.126.11.236.1203597326.squirrel@webmail.cs.its.ac.id> Message-ID: On Thu, Feb 21, 2008 at 4:35 AM, wrote: > > File System, line unknown, in Read > IOError: Unable to read data from the transport connection: Cannot access > a disposed object. > Object name: 'System.Net.Sockets.Socket'.. This is a known issue in IronPython. You can work around it by using Seo's implementation of the socket module. If you're not already using it, download "IronPython Community Edition" from http://fepy.sourceforge.net. Then to replace the built-in socket module, you'll need to do something like this: import os, sys, imp sys.modules['socket'] = module = imp.new_module('socket') execfile('..\\lib\\socket.py', module.__dict__) import xmlrpclib server = xmlrpclib.Server('http://localhost:4567') month = server.getMonth(2002, 8) I've tested this and it works. (Code shamelessly stolen from Birsch's recent BeautifulSoup example.) -- Curt Hagenlocher curt at hagenlocher.org From fuzzyman at voidspace.org.uk Thu Feb 21 14:44:16 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Thu, 21 Feb 2008 13:44:16 +0000 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> Message-ID: <47BD8030.4000008@voidspace.org.uk> Birsch wrote: > Thanks Michael and Dino. > > I'll prof and send update. Got a good profiler recommendation for .Net? > Meanwhile I noticed the sample site below causes BeautifulSoup to > generate quite a few [python] exceptions during __init__. Does > IronPython handle exceptions significantly slower than CPtyhon? I wouldn't make any assumptions about what is taking the time until you have profiled. :-) Michael http://www.manning.com/foord > > Repro code is simple (just build a BeautifulSoup obj with mininova's > home page). > Here are the .py and .cs I used to time the diffs: > > *bstest.py:* > #Bypass CPython default socket implementation with IPCE/FePy > import imp, os, sys > sys.modules['socket'] = module = imp.new_module('socket') > execfile('socket.py', module.__dict__) > > from BeautifulSoup import BeautifulSoup > from urllib import urlopen > import datetime > > def getContent(url): > #Download html data > startTime = datetime.datetime.now() > print "Getting url", url > html = urlopen(url).read() > print "Time taken:", datetime.datetime.now() - startTime > > #Make soup > startTime = datetime.datetime.now() > print "Making soup..." > soup = BeautifulSoup(markup=html) > print "Time taken:", datetime.datetime.now() - startTime > > if __name__ == "__main__": > print getContent("www.mininova.org ") > > > *C#:* > using System; > using System.Collections.Generic; > using System.Text; > using IronPython.Hosting; > > namespace IronPythonBeautifulSoupTest > { > public class Program > { > public static void Main(string[] args) > { > //Init > System.Console.WriteLine("Starting..."); > DateTime start = DateTime.Now; > PythonEngine engine = new PythonEngine(); > > //Add paths: > //BeautifulSoup.py, socket.py, bstest.py located on exe dir > engine.AddToPath(@"."); > //CPython Lib (replace with your own) > engine.AddToPath(@"D:\Dev\Python\Lib"); > > //Import and load > TimeSpan span = DateTime.Now - start; > System.Console.WriteLine("[1] Import: " + span.TotalSeconds); > DateTime d = DateTime.Now; > engine.ExecuteFile(@"bstest.py"); > span = DateTime.Now - d; > System.Console.WriteLine("[2] Load: " + span.TotalSeconds); > > //Execute > d = DateTime.Now; > engine.Execute("getContent(\"http://www.mininova.org\ > ")"); > span = DateTime.Now - d; > System.Console.WriteLine("[3] Execute: " + span.TotalSeconds); > span = DateTime.Now - start; > System.Console.WriteLine("Total: " + span.TotalSeconds); > } > } > } > > > > On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland > > > wrote: > > We've actually had this issue reported once before a long time ago > - it's a very low CodePlex ID - > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 > > We haven't had a chance to investigate the end-to-end scenario. > If someone could come up with a smaller simpler repro that'd be > great. Otherwise we haven't forgotten about it we've just had > more immediately pressing issues to work on :(. > > -----Original Message----- > From: users-bounces at lists.ironpython.com > > [mailto:users-bounces at lists.ironpython.com > ] On Behalf Of Michael > Foord > Sent: Wednesday, February 20, 2008 5:20 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Slow Performance of CPython libs? > > Birsch wrote: > > Hi - We've been using IronPython successfully to allow extensibility > > of our application. > > > > Overall we are happy with the performance, with the exception of > > BeautifulSoup which seems to run very slowly: x5 or more time to > > execute compared to CPython. > > > > Most of the time seems to be spent during __init__() of BS, > where the > > markup is parsed. > > > > We suspect this has to do with the fact that our CPython env is > > executing .pyc files and can precompile its libs, while the > IronPython > > environment compiles each iteration. We couldn't find a way to > > pre-compile the libs and then introduce them into the code, but > in any > > case this will result in a large management overhead since the > amount > > of CPython libs we expose to our users contains 100's of modules. > > > > Any ideas on how to optimize? > > I think it is worth doing real profiling to find out where the time is > being spent during parsing. > > If it is spending most of the time in '__init__' then the time is > probably not spent in importing - so compilation isn't relevant and it > is a runtime performance issue. (Importing is much slower with > IronPython and at Resolver Systems we do use precompiled binaries > - but > strangely enough it doesn't provide much of a performance gain.) > > Michael > http://www.manning.com/foord > > > > > Thanks, > > -Birsch > > > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 runtime DLLs > > (this was done to overcome library incompatibilities and network > > errors). However, the relevant slow .py code (mainly SGMLParser and > > BeautifulSoup) is the same. > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From Jon.Cooper at arrowgrass.com Thu Feb 21 15:15:41 2008 From: Jon.Cooper at arrowgrass.com (Jon Cooper) Date: Thu, 21 Feb 2008 14:15:41 +0000 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> Message-ID: <7847E919C98EA24E8777BA06ACD17A1643B10B@aglonexh01.arrowgrass.local> I like the ANTS Profiler, and there's also one in VS2005 Team that is supposed to be okay. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Birsch Sent: Thursday, February 21, 2008 7:36 AM To: Discussion of IronPython Subject: Re: [IronPython] Slow Performance of CPython libs? Thanks Michael and Dino. I'll prof and send update. Got a good profiler recommendation for .Net? Meanwhile I noticed the sample site below causes BeautifulSoup to generate quite a few [python] exceptions during __init__. Does IronPython handle exceptions significantly slower than CPtyhon? Repro code is simple (just build a BeautifulSoup obj with mininova's home page). Here are the .py and .cs I used to time the diffs: bstest.py: #Bypass CPython default socket implementation with IPCE/FePy import imp, os, sys sys.modules['socket'] = module = imp.new_module('socket') execfile('socket.py', module.__dict__) from BeautifulSoup import BeautifulSoup from urllib import urlopen import datetime def getContent(url): #Download html data startTime = datetime.datetime.now() print "Getting url", url html = urlopen(url).read() print "Time taken:", datetime.datetime.now() - startTime #Make soup startTime = datetime.datetime.now() print "Making soup..." soup = BeautifulSoup(markup=html) print "Time taken:", datetime.datetime.now() - startTime if __name__ == "__main__": print getContent("www.mininova.org") C#: using System; using System.Collections.Generic; using System.Text; using IronPython.Hosting; namespace IronPythonBeautifulSoupTest { public class Program { public static void Main(string[] args) { //Init System.Console.WriteLine("Starting..."); DateTime start = DateTime.Now; PythonEngine engine = new PythonEngine(); //Add paths: //BeautifulSoup.py, socket.py, bstest.py located on exe dir engine.AddToPath(@"."); //CPython Lib (replace with your own) engine.AddToPath(@"D:\Dev\Python\Lib"); //Import and load TimeSpan span = DateTime.Now - start; System.Console.WriteLine("[1] Import: " + span.TotalSeconds); DateTime d = DateTime.Now; engine.ExecuteFile(@"bstest.py"); span = DateTime.Now - d; System.Console.WriteLine("[2] Load: " + span.TotalSeconds); //Execute d = DateTime.Now; engine.Execute("getContent(\"http://www.mininova.org\")"); span = DateTime.Now - d; System.Console.WriteLine("[3] Execute: " + span.TotalSeconds); span = DateTime.Now - start; System.Console.WriteLine("Total: " + span.TotalSeconds); } } } On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland > wrote: We've actually had this issue reported once before a long time ago - it's a very low CodePlex ID - http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 We haven't had a chance to investigate the end-to-end scenario. If someone could come up with a smaller simpler repro that'd be great. Otherwise we haven't forgotten about it we've just had more immediately pressing issues to work on :(. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: Wednesday, February 20, 2008 5:20 AM To: Discussion of IronPython Subject: Re: [IronPython] Slow Performance of CPython libs? Birsch wrote: > Hi - We've been using IronPython successfully to allow extensibility > of our application. > > Overall we are happy with the performance, with the exception of > BeautifulSoup which seems to run very slowly: x5 or more time to > execute compared to CPython. > > Most of the time seems to be spent during __init__() of BS, where the > markup is parsed. > > We suspect this has to do with the fact that our CPython env is > executing .pyc files and can precompile its libs, while the IronPython > environment compiles each iteration. We couldn't find a way to > pre-compile the libs and then introduce them into the code, but in any > case this will result in a large management overhead since the amount > of CPython libs we expose to our users contains 100's of modules. > > Any ideas on how to optimize? I think it is worth doing real profiling to find out where the time is being spent during parsing. If it is spending most of the time in '__init__' then the time is probably not spent in importing - so compilation isn't relevant and it is a runtime performance issue. (Importing is much slower with IronPython and at Resolver Systems we do use precompiled binaries - but strangely enough it doesn't provide much of a performance gain.) Michael http://www.manning.com/foord > > Thanks, > -Birsch > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 runtime DLLs > (this was done to overcome library incompatibilities and network > errors). However, the relevant slow .py code (mainly SGMLParser and > BeautifulSoup) is the same. > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ________________________________ Arrowgrass Capital Partners (US) LP is a limited partnership registered in the State of Delaware. This message is for the named person's use only. It may contain confidential, proprietary or legally privileged information. No confidentiality or privilege is waived or lost by any transmission errors. If you receive this message in error, please immediately delete it and all copies of it from your system, destroy any hard copies of it and notify the sender. You must not, directly or indirectly, use, disclose, distribute, print, or copy any part of this message if you are not the intended recipient. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Thu Feb 21 17:28:50 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Thu, 21 Feb 2008 08:28:50 -0800 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <20253b0c0802210454g1f63c09ao101cce9a220f0f2b@mail.gmail.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> <20253b0c0802210454g1f63c09ao101cce9a220f0f2b@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4EB6CA3@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Throwing exceptions is a whole lot slower. But for what it's worth the cost of try/except though is much cheaper on IronPython if no exception is thrown. Here's the exception results on PyBench. Note these are actually results I happen to have on my machine from a while ago - but nothing's been done to change this part of the perf story in some time: TryExcept: 56ms 3ms +1938.4% 56ms 6ms +830.4% TryRaiseExcept: 88ms 2543ms -96.6% 88ms 2556ms -96.5% Cpython took 88ms, IronPython took 2543ms. And clearly throwing exceptions is quite expensive. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Davy Mitchell Sent: Thursday, February 21, 2008 4:55 AM To: Discussion of IronPython Subject: Re: [IronPython] Slow Performance of CPython libs? On Thu, Feb 21, 2008 at 12:35 PM, Birsch wrote: > quite a few [python] exceptions during __init__. Does IronPython handle > exceptions significantly slower than CPtyhon? This has been my experience - I've worked round it by editing modules to avoid nasty bits. Not always practical but saved many seconds in my case. Cheers, Davy -- Davy Mitchell Blog - http://www.latedecember.co.uk/sites/personal/davy/ Twitter - http://twitter.com/daftspaniel Skype - daftspaniel needgod.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From birsch at gmail.com Thu Feb 21 17:30:12 2008 From: birsch at gmail.com (Birsch) Date: Thu, 21 Feb 2008 18:30:12 +0200 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> Message-ID: <1e4778de0802210830s60e4f13eue81dd421eca4677@mail.gmail.com> I took on Cooper's advice and profiled with ANTS. Here are the top methods: Namespace Method name Time (sec.) Time with children (sec.) Hit count Source file System.Text.RegularExpressions RegexInterpreter.Go() 37.0189 94.4676 13689612 System.Text.RegularExpressions RegexInterpreter.Operator() 6.2411 6.2411 131146274 System.Text.RegularExpressions RegexInterpreter.Advance(int i) 5.9264 8.7202 66000263 System.Text.RegularExpressions RegexInterpreter.SetOperator(int op) 5.5750 5.5750 131146274 System.Text.RegularExpressions RegexInterpreter.Backtrack() 5.5692 9.4895 37781343 IronPython.Runtime.Operations Ops.CallWithContext(ICallerContext context, object func, object arg0, object arg1) 5.5572 114.5245 79754 IronPython.Runtime.Calls Method.Call(ICallerContext context, object arg0) 4.9052 114.8251 50886 IronPython.Runtime.Calls PythonFunction.CallInstance(ICallerContext context, object arg0, object arg1) 4.8876 114.8059 50886 IronPython.Runtime.Calls Function2.Call(ICallerContext context, object arg0, object arg1) 4.6400 114.5471 47486 IronPython.Runtime.Operations Ops.CallWithContext(ICallerContext context, object func, object arg0) 4.2344 114.1604 146658 System.Text.RegularExpressions RegexBoyerMoore.Scan(string text, int index, int beglimit, int endlimit) 3.6465 3.6465 13678131 System.Text.RegularExpressions RegexCharClass.CharInClassRecursive(char ch, string set, int start) 3.6288 5.7113 31508162 System.Text.RegularExpressions RegexInterpreter.Goto(int newpos) 3.2058 5.1470 27364668 System.Text.RegularExpressions RegexInterpreter.Operand(int i) 3.1923 3.1923 73230687 System.Text.RegularExpressions RegexRunner.EnsureStorage() 3.0803 3.0803 51474823 System.Text.RegularExpressions RegexCharClass.CharInClass(char ch, string set) 3.0713 8.7827 31508162 IronPython.Runtime.Calls Method.Call(ICallerContext context, object arg0, object arg1) 2.9821 7.8675 15012 IronPython.Runtime.Calls PythonFunction.CallInstance(ICallerContext context, object arg0, object arg1, object arg2) 2.9794 7.8639 15012 System.Text.RegularExpressions RegexInterpreter.Forwardcharnext() 2.8852 2.8852 62865185 System.Text.RegularExpressions RegexInterpreter.Forwardchars() 2.8279 2.8279 59436277 System.Text.RegularExpressions RegexCharClass.CharInClassInternal(char ch, string set, int start, int mySetLength, int myCategoryLength) 2.0632 2.0826 31508162 System.Text.RegularExpressions RegexRunner.Scan(Regex regex, string text, int textbeg, int textend, int textstart, int prevlen, bool quick) 1.8376 101.7226 43009 System.Text.RegularExpressions RegexInterpreter.FindFirstChar() 1.6405 5.3456 13701755 IronPython.Runtime.Types OldClass.TryLookupSlot(SymbolId name, out object ret) 1.5573 2.8124 389516 IronPython.Runtime.Operations Ops.GetAttr(ICallerContext context, object o, SymbolId name) 1.5365 5.3456 558524 System.Text.RegularExpressions RegexInterpreter.Textpos() 1.4020 1.4020 32648926 System.Text.RegularExpressions RegexInterpreter.Advance() 1.1916 2.9526 13703950 System.Text.RegularExpressions RegexInterpreter.Textto(int newpos) 1.1218 1.1218 24120890 System.Text.RegularExpressions RegexInterpreter.TrackPeek() 1.0579 1.0579 24120894 System.Text.RegularExpressions Regex.Run(bool quick, int prevlen, string input, int beginning, int length, int startat) 0.7280 102.4644 43009 System.Text.RegularExpressions RegexInterpreter.TrackPush(int I1) 0.6834 0.6834 13745149 System.Text.RegularExpressions RegexInterpreter.StackPush(int I1) 0.6542 0.6542 13703955 System.Text.RegularExpressions RegexInterpreter.TrackPop() 0.6068 0.6068 13663035 System.Text.RegularExpressions RegexInterpreter.TrackPush() 0.6049 0.6049 13708230 System.Text.RegularExpressions RegexInterpreter.StackPop() 0.5836 0.5836 13703956 System.Text.RegularExpressions RegexInterpreter.Bump() 0.4987 0.4987 10472790 System.Text.RegularExpressions RegexInterpreter.TrackPush(int I1, int I2) 0.4864 0.4864 10472790 System.Text.RegularExpressions RegexInterpreter.TrackPeek(int i) 0.4663 0.4663 10457859 System.Text.RegularExpressions RegexInterpreter.TrackPop(int framesize) 0.4396 0.4396 10457859 Moving up the stack of regex.Go(), most calls originate from sgmllib's parse_starttag. HTH, -Birsch On Thu, Feb 21, 2008 at 2:35 PM, Birsch wrote: > Thanks Michael and Dino. > > I'll prof and send update. Got a good profiler recommendation for .Net? > Meanwhile I noticed the sample site below causes BeautifulSoup to generate > quite a few [python] exceptions during __init__. Does IronPython handle > exceptions significantly slower than CPtyhon? > > Repro code is simple (just build a BeautifulSoup obj with mininova's home > page). > Here are the .py and .cs I used to time the diffs: > > *bstest.py:* > #Bypass CPython default socket implementation with IPCE/FePy > import imp, os, sys > sys.modules['socket'] = module = imp.new_module('socket') > execfile('socket.py', module.__dict__) > > from BeautifulSoup import BeautifulSoup > from urllib import urlopen > import datetime > > def getContent(url): > #Download html data > startTime = datetime.datetime.now() > print "Getting url", url > html = urlopen(url).read() > print "Time taken:", datetime.datetime.now() - startTime > > #Make soup > startTime = datetime.datetime.now() > print "Making soup..." > soup = BeautifulSoup(markup=html) > print "Time taken:", datetime.datetime.now() - startTime > > if __name__ == "__main__": > print getContent("www.mininova.org") > > > *C#:* > using System; > using System.Collections.Generic; > using System.Text; > using IronPython.Hosting; > > namespace IronPythonBeautifulSoupTest > { > public class Program > { > public static void Main(string[] args) > { > //Init > System.Console.WriteLine("Starting..."); > DateTime start = DateTime.Now; > PythonEngine engine = new PythonEngine(); > > //Add paths: > //BeautifulSoup.py, socket.py, bstest.py located on exe dir > engine.AddToPath(@"."); > //CPython Lib (replace with your own) > engine.AddToPath(@"D:\Dev\Python\Lib"); > > //Import and load > TimeSpan span = DateTime.Now - start; > System.Console.WriteLine("[1] Import: " + span.TotalSeconds); > DateTime d = DateTime.Now; > engine.ExecuteFile(@"bstest.py"); > span = DateTime.Now - d; > System.Console.WriteLine("[2] Load: " + span.TotalSeconds); > > //Execute > d = DateTime.Now; > engine.Execute("getContent(\"http://www.mininova.org\")"); > span = DateTime.Now - d; > System.Console.WriteLine("[3] Execute: " + span.TotalSeconds); > span = DateTime.Now - start; > System.Console.WriteLine("Total: " + span.TotalSeconds); > > } > } > } > > > > On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland < > dinov at exchange.microsoft.com> wrote: > > > We've actually had this issue reported once before a long time ago - > > it's a very low CodePlex ID - > > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 > > > > We haven't had a chance to investigate the end-to-end scenario. If > > someone could come up with a smaller simpler repro that'd be great. > > Otherwise we haven't forgotten about it we've just had more immediately > > pressing issues to work on :(. > > > > -----Original Message----- > > From: users-bounces at lists.ironpython.com [mailto: > > users-bounces at lists.ironpython.com] On Behalf Of Michael Foord > > Sent: Wednesday, February 20, 2008 5:20 AM > > To: Discussion of IronPython > > Subject: Re: [IronPython] Slow Performance of CPython libs? > > > > Birsch wrote: > > > Hi - We've been using IronPython successfully to allow extensibility > > > of our application. > > > > > > Overall we are happy with the performance, with the exception of > > > BeautifulSoup which seems to run very slowly: x5 or more time to > > > execute compared to CPython. > > > > > > Most of the time seems to be spent during __init__() of BS, where the > > > markup is parsed. > > > > > > We suspect this has to do with the fact that our CPython env is > > > executing .pyc files and can precompile its libs, while the IronPython > > > environment compiles each iteration. We couldn't find a way to > > > pre-compile the libs and then introduce them into the code, but in any > > > case this will result in a large management overhead since the amount > > > of CPython libs we expose to our users contains 100's of modules. > > > > > > Any ideas on how to optimize? > > > > I think it is worth doing real profiling to find out where the time is > > being spent during parsing. > > > > If it is spending most of the time in '__init__' then the time is > > probably not spent in importing - so compilation isn't relevant and it > > is a runtime performance issue. (Importing is much slower with > > IronPython and at Resolver Systems we do use precompiled binaries - but > > strangely enough it doesn't provide much of a performance gain.) > > > > Michael > > http://www.manning.com/foord > > > > > > > > Thanks, > > > -Birsch > > > > > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 runtime DLLs > > > (this was done to overcome library incompatibilities and network > > > errors). However, the relevant slow .py code (mainly SGMLParser and > > > BeautifulSoup) is the same. > > > > > ------------------------------------------------------------------------ > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Thu Feb 21 18:30:50 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Thu, 21 Feb 2008 09:30:50 -0800 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <1e4778de0802210830s60e4f13eue81dd421eca4677@mail.gmail.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> <1e4778de0802210830s60e4f13eue81dd421eca4677@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4EB6CCF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Do you know if the same reg ex is being used repeatedly? If so maybe we can cache & compile the regex instead of interpretting it all the time. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Birsch Sent: Thursday, February 21, 2008 8:30 AM To: Discussion of IronPython Subject: Re: [IronPython] Slow Performance of CPython libs? I took on Cooper's advice and profiled with ANTS. Here are the top methods: Namespace Method name Time (sec.) Time with children (sec.) Hit count Source file System.Text.RegularExpressions RegexInterpreter.Go() 37.0189 94.4676 13689612 System.Text.RegularExpressions RegexInterpreter.Operator() 6.2411 6.2411 131146274 System.Text.RegularExpressions RegexInterpreter.Advance(int i) 5.9264 8.7202 66000263 System.Text.RegularExpressions RegexInterpreter.SetOperator(int op) 5.5750 5.5750 131146274 System.Text.RegularExpressions RegexInterpreter.Backtrack() 5.5692 9.4895 37781343 IronPython.Runtime.Operations Ops.CallWithContext(ICallerContext context, object func, object arg0, object arg1) 5.5572 114.5245 79754 IronPython.Runtime.Calls Method.Call(ICallerContext context, object arg0) 4.9052 114.8251 50886 IronPython.Runtime.Calls PythonFunction.CallInstance(ICallerContext context, object arg0, object arg1) 4.8876 114.8059 50886 IronPython.Runtime.Calls Function2.Call(ICallerContext context, object arg0, object arg1) 4.6400 114.5471 47486 IronPython.Runtime.Operations Ops.CallWithContext(ICallerContext context, object func, object arg0) 4.2344 114.1604 146658 System.Text.RegularExpressions RegexBoyerMoore.Scan(string text, int index, int beglimit, int endlimit) 3.6465 3.6465 13678131 System.Text.RegularExpressions RegexCharClass.CharInClassRecursive(char ch, string set, int start) 3.6288 5.7113 31508162 System.Text.RegularExpressions RegexInterpreter.Goto(int newpos) 3.2058 5.1470 27364668 System.Text.RegularExpressions RegexInterpreter.Operand(int i) 3.1923 3.1923 73230687 System.Text.RegularExpressions RegexRunner.EnsureStorage() 3.0803 3.0803 51474823 System.Text.RegularExpressions RegexCharClass.CharInClass(char ch, string set) 3.0713 8.7827 31508162 IronPython.Runtime.Calls Method.Call(ICallerContext context, object arg0, object arg1) 2.9821 7.8675 15012 IronPython.Runtime.Calls PythonFunction.CallInstance(ICallerContext context, object arg0, object arg1, object arg2) 2.9794 7.8639 15012 System.Text.RegularExpressions RegexInterpreter.Forwardcharnext() 2.8852 2.8852 62865185 System.Text.RegularExpressions RegexInterpreter.Forwardchars() 2.8279 2.8279 59436277 System.Text.RegularExpressions RegexCharClass.CharInClassInternal(char ch, string set, int start, int mySetLength, int myCategoryLength) 2.0632 2.0826 31508162 System.Text.RegularExpressions RegexRunner.Scan(Regex regex, string text, int textbeg, int textend, int textstart, int prevlen, bool quick) 1.8376 101.7226 43009 System.Text.RegularExpressions RegexInterpreter.FindFirstChar() 1.6405 5.3456 13701755 IronPython.Runtime.Types OldClass.TryLookupSlot(SymbolId name, out object ret) 1.5573 2.8124 389516 IronPython.Runtime.Operations Ops.GetAttr(ICallerContext context, object o, SymbolId name) 1.5365 5.3456 558524 System.Text.RegularExpressions RegexInterpreter.Textpos() 1.4020 1.4020 32648926 System.Text.RegularExpressions RegexInterpreter.Advance() 1.1916 2.9526 13703950 System.Text.RegularExpressions RegexInterpreter.Textto(int newpos) 1.1218 1.1218 24120890 System.Text.RegularExpressions RegexInterpreter.TrackPeek() 1.0579 1.0579 24120894 System.Text.RegularExpressions Regex.Run(bool quick, int prevlen, string input, int beginning, int length, int startat) 0.7280 102.4644 43009 System.Text.RegularExpressions RegexInterpreter.TrackPush(int I1) 0.6834 0.6834 13745149 System.Text.RegularExpressions RegexInterpreter.StackPush(int I1) 0.6542 0.6542 13703955 System.Text.RegularExpressions RegexInterpreter.TrackPop() 0.6068 0.6068 13663035 System.Text.RegularExpressions RegexInterpreter.TrackPush() 0.6049 0.6049 13708230 System.Text.RegularExpressions RegexInterpreter.StackPop() 0.5836 0.5836 13703956 System.Text.RegularExpressions RegexInterpreter.Bump() 0.4987 0.4987 10472790 System.Text.RegularExpressions RegexInterpreter.TrackPush(int I1, int I2) 0.4864 0.4864 10472790 System.Text.RegularExpressions RegexInterpreter.TrackPeek(int i) 0.4663 0.4663 10457859 System.Text.RegularExpressions RegexInterpreter.TrackPop(int framesize) 0.4396 0.4396 10457859 Moving up the stack of regex.Go(), most calls originate from sgmllib's parse_starttag. HTH, -Birsch On Thu, Feb 21, 2008 at 2:35 PM, Birsch > wrote: Thanks Michael and Dino. I'll prof and send update. Got a good profiler recommendation for .Net? Meanwhile I noticed the sample site below causes BeautifulSoup to generate quite a few [python] exceptions during __init__. Does IronPython handle exceptions significantly slower than CPtyhon? Repro code is simple (just build a BeautifulSoup obj with mininova's home page). Here are the .py and .cs I used to time the diffs: bstest.py: #Bypass CPython default socket implementation with IPCE/FePy import imp, os, sys sys.modules['socket'] = module = imp.new_module('socket') execfile('socket.py', module.__dict__) from BeautifulSoup import BeautifulSoup from urllib import urlopen import datetime def getContent(url): #Download html data startTime = datetime.datetime.now() print "Getting url", url html = urlopen(url).read() print "Time taken:", datetime.datetime.now() - startTime #Make soup startTime = datetime.datetime.now() print "Making soup..." soup = BeautifulSoup(markup=html) print "Time taken:", datetime.datetime.now() - startTime if __name__ == "__main__": print getContent("www.mininova.org") C#: using System; using System.Collections.Generic; using System.Text; using IronPython.Hosting; namespace IronPythonBeautifulSoupTest { public class Program { public static void Main(string[] args) { //Init System.Console.WriteLine("Starting..."); DateTime start = DateTime.Now; PythonEngine engine = new PythonEngine(); //Add paths: //BeautifulSoup.py, socket.py, bstest.py located on exe dir engine.AddToPath(@"."); //CPython Lib (replace with your own) engine.AddToPath(@"D:\Dev\Python\Lib"); //Import and load TimeSpan span = DateTime.Now - start; System.Console.WriteLine("[1] Import: " + span.TotalSeconds); DateTime d = DateTime.Now; engine.ExecuteFile(@"bstest.py"); span = DateTime.Now - d; System.Console.WriteLine("[2] Load: " + span.TotalSeconds); //Execute d = DateTime.Now; engine.Execute("getContent(\"http://www.mininova.org\")"); span = DateTime.Now - d; System.Console.WriteLine("[3] Execute: " + span.TotalSeconds); span = DateTime.Now - start; System.Console.WriteLine("Total: " + span.TotalSeconds); } } } On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland > wrote: We've actually had this issue reported once before a long time ago - it's a very low CodePlex ID - http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 We haven't had a chance to investigate the end-to-end scenario. If someone could come up with a smaller simpler repro that'd be great. Otherwise we haven't forgotten about it we've just had more immediately pressing issues to work on :(. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: Wednesday, February 20, 2008 5:20 AM To: Discussion of IronPython Subject: Re: [IronPython] Slow Performance of CPython libs? Birsch wrote: > Hi - We've been using IronPython successfully to allow extensibility > of our application. > > Overall we are happy with the performance, with the exception of > BeautifulSoup which seems to run very slowly: x5 or more time to > execute compared to CPython. > > Most of the time seems to be spent during __init__() of BS, where the > markup is parsed. > > We suspect this has to do with the fact that our CPython env is > executing .pyc files and can precompile its libs, while the IronPython > environment compiles each iteration. We couldn't find a way to > pre-compile the libs and then introduce them into the code, but in any > case this will result in a large management overhead since the amount > of CPython libs we expose to our users contains 100's of modules. > > Any ideas on how to optimize? I think it is worth doing real profiling to find out where the time is being spent during parsing. If it is spending most of the time in '__init__' then the time is probably not spent in importing - so compilation isn't relevant and it is a runtime performance issue. (Importing is much slower with IronPython and at Resolver Systems we do use precompiled binaries - but strangely enough it doesn't provide much of a performance gain.) Michael http://www.manning.com/foord > > Thanks, > -Birsch > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 runtime DLLs > (this was done to overcome library incompatibilities and network > errors). However, the relevant slow .py code (mainly SGMLParser and > BeautifulSoup) is the same. > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From birsch at gmail.com Thu Feb 21 19:04:46 2008 From: birsch at gmail.com (Birsch) Date: Thu, 21 Feb 2008 20:04:46 +0200 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF4EB6CCF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> <1e4778de0802210830s60e4f13eue81dd421eca4677@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4EB6CCF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <1e4778de0802211004k6a3fbdf4i79d8de7fd243c6c1@mail.gmail.com> I checked both sgmllib.py and BeautifulSoup.py - and it seems both are reusing the same regexps (searched for re.compile). I think your suggestion is very relevant in this case. It makes sense to replicate the "compile once use many" behavior that is commonly used with regexp. -Birsch On Thu, Feb 21, 2008 at 7:30 PM, Dino Viehland wrote: > Do you know if the same reg ex is being used repeatedly? If so maybe we > can cache & compile the regex instead of interpretting it all the time. > > > > *From:* users-bounces at lists.ironpython.com [mailto: > users-bounces at lists.ironpython.com] *On Behalf Of *Birsch > *Sent:* Thursday, February 21, 2008 8:30 AM > > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] Slow Performance of CPython libs? > > > > I took on Cooper's advice and profiled with ANTS. Here are the top > methods: > > *Namespace* > > *Method name* > > *Time (sec.)* > > *Time with children (sec.)* > > *Hit count* > > *Source file* > > System.Text.RegularExpressions > > RegexInterpreter.Go() > > 37.0189 > > 94.4676 > > 13689612 > > System.Text.RegularExpressions > > RegexInterpreter.Operator() > > 6.2411 > > 6.2411 > > 131146274 > > System.Text.RegularExpressions > > RegexInterpreter.Advance(int i) > > 5.9264 > > 8.7202 > > 66000263 > > System.Text.RegularExpressions > > RegexInterpreter.SetOperator(int op) > > 5.5750 > > 5.5750 > > 131146274 > > System.Text.RegularExpressions > > RegexInterpreter.Backtrack() > > 5.5692 > > 9.4895 > > 37781343 > > IronPython.Runtime.Operations > > Ops.CallWithContext(ICallerContext context, object func, object arg0, > object arg1) > > 5.5572 > > 114.5245 > > 79754 > > IronPython.Runtime.Calls > > Method.Call(ICallerContext context, object arg0) > > 4.9052 > > 114.8251 > > 50886 > > IronPython.Runtime.Calls > > PythonFunction.CallInstance(ICallerContext context, object arg0, object > arg1) > > 4.8876 > > 114.8059 > > 50886 > > IronPython.Runtime.Calls > > Function2.Call(ICallerContext context, object arg0, object arg1) > > 4.6400 > > 114.5471 > > 47486 > > IronPython.Runtime.Operations > > Ops.CallWithContext(ICallerContext context, object func, object arg0) > > 4.2344 > > 114.1604 > > 146658 > > System.Text.RegularExpressions > > RegexBoyerMoore.Scan(string text, int index, int beglimit, int endlimit) > > 3.6465 > > 3.6465 > > 13678131 > > System.Text.RegularExpressions > > RegexCharClass.CharInClassRecursive(char ch, string set, int start) > > 3.6288 > > 5.7113 > > 31508162 > > System.Text.RegularExpressions > > RegexInterpreter.Goto(int newpos) > > 3.2058 > > 5.1470 > > 27364668 > > System.Text.RegularExpressions > > RegexInterpreter.Operand(int i) > > 3.1923 > > 3.1923 > > 73230687 > > System.Text.RegularExpressions > > RegexRunner.EnsureStorage() > > 3.0803 > > 3.0803 > > 51474823 > > System.Text.RegularExpressions > > RegexCharClass.CharInClass(char ch, string set) > > 3.0713 > > 8.7827 > > 31508162 > > IronPython.Runtime.Calls > > Method.Call(ICallerContext context, object arg0, object arg1) > > 2.9821 > > 7.8675 > > 15012 > > IronPython.Runtime.Calls > > PythonFunction.CallInstance(ICallerContext context, object arg0, object > arg1, object arg2) > > 2.9794 > > 7.8639 > > 15012 > > System.Text.RegularExpressions > > RegexInterpreter.Forwardcharnext() > > 2.8852 > > 2.8852 > > 62865185 > > System.Text.RegularExpressions > > RegexInterpreter.Forwardchars() > > 2.8279 > > 2.8279 > > 59436277 > > System.Text.RegularExpressions > > RegexCharClass.CharInClassInternal(char ch, string set, int start, int > mySetLength, int myCategoryLength) > > 2.0632 > > 2.0826 > > 31508162 > > System.Text.RegularExpressions > > RegexRunner.Scan(Regex regex, string text, int textbeg, int textend, int > textstart, int prevlen, bool quick) > > 1.8376 > > 101.7226 > > 43009 > > System.Text.RegularExpressions > > RegexInterpreter.FindFirstChar() > > 1.6405 > > 5.3456 > > 13701755 > > IronPython.Runtime.Types > > OldClass.TryLookupSlot(SymbolId name, out object ret) > > 1.5573 > > 2.8124 > > 389516 > > IronPython.Runtime.Operations > > Ops.GetAttr(ICallerContext context, object o, SymbolId name) > > 1.5365 > > 5.3456 > > 558524 > > System.Text.RegularExpressions > > RegexInterpreter.Textpos() > > 1.4020 > > 1.4020 > > 32648926 > > System.Text.RegularExpressions > > RegexInterpreter.Advance() > > 1.1916 > > 2.9526 > > 13703950 > > System.Text.RegularExpressions > > RegexInterpreter.Textto(int newpos) > > 1.1218 > > 1.1218 > > 24120890 > > System.Text.RegularExpressions > > RegexInterpreter.TrackPeek() > > 1.0579 > > 1.0579 > > 24120894 > > System.Text.RegularExpressions > > Regex.Run(bool quick, int prevlen, string input, int beginning, int > length, int startat) > > 0.7280 > > 102.4644 > > 43009 > > System.Text.RegularExpressions > > RegexInterpreter.TrackPush(int I1) > > 0.6834 > > 0.6834 > > 13745149 > > System.Text.RegularExpressions > > RegexInterpreter.StackPush(int I1) > > 0.6542 > > 0.6542 > > 13703955 > > System.Text.RegularExpressions > > RegexInterpreter.TrackPop() > > 0.6068 > > 0.6068 > > 13663035 > > System.Text.RegularExpressions > > RegexInterpreter.TrackPush() > > 0.6049 > > 0.6049 > > 13708230 > > System.Text.RegularExpressions > > RegexInterpreter.StackPop() > > 0.5836 > > 0.5836 > > 13703956 > > System.Text.RegularExpressions > > RegexInterpreter.Bump() > > 0.4987 > > 0.4987 > > 10472790 > > System.Text.RegularExpressions > > RegexInterpreter.TrackPush(int I1, int I2) > > 0.4864 > > 0.4864 > > 10472790 > > System.Text.RegularExpressions > > RegexInterpreter.TrackPeek(int i) > > 0.4663 > > 0.4663 > > 10457859 > > System.Text.RegularExpressions > > RegexInterpreter.TrackPop(int framesize) > > 0.4396 > > 0.4396 > > 10457859 > > > Moving up the stack of regex.Go(), most calls originate from sgmllib's > parse_starttag. > > HTH, > -Birsch > > On Thu, Feb 21, 2008 at 2:35 PM, Birsch wrote: > > Thanks Michael and Dino. > > I'll prof and send update. Got a good profiler recommendation for .Net? > Meanwhile I noticed the sample site below causes BeautifulSoup to generate > quite a few [python] exceptions during __init__. Does IronPython handle > exceptions significantly slower than CPtyhon? > > Repro code is simple (just build a BeautifulSoup obj with mininova's home > page). > Here are the .py and .cs I used to time the diffs: > > *bstest.py:* > #Bypass CPython default socket implementation with IPCE/FePy > import imp, os, sys > sys.modules['socket'] = module = imp.new_module('socket') > execfile('socket.py', module.__dict__) > > from BeautifulSoup import BeautifulSoup > from urllib import urlopen > import datetime > > def getContent(url): > #Download html data > startTime = datetime.datetime.now() > print "Getting url", url > html = urlopen(url).read() > print "Time taken:", datetime.datetime.now() - startTime > > #Make soup > startTime = datetime.datetime.now() > print "Making soup..." > soup = BeautifulSoup(markup=html) > print "Time taken:", datetime.datetime.now() - startTime > > if __name__ == "__main__": > print getContent("www.mininova.org") > > > *C#:* > using System; > using System.Collections.Generic; > using System.Text; > using IronPython.Hosting; > > namespace IronPythonBeautifulSoupTest > { > public class Program > { > public static void Main(string[] args) > { > //Init > System.Console.WriteLine("Starting..."); > DateTime start = DateTime.Now; > PythonEngine engine = new PythonEngine(); > > //Add paths: > //BeautifulSoup.py, socket.py, bstest.py located on exe dir > engine.AddToPath(@"."); > //CPython Lib (replace with your own) > engine.AddToPath(@"D:\Dev\Python\Lib"); > > //Import and load > TimeSpan span = DateTime.Now - start; > System.Console.WriteLine("[1] Import: " + span.TotalSeconds); > DateTime d = DateTime.Now; > engine.ExecuteFile(@"bstest.py"); > span = DateTime.Now - d; > System.Console.WriteLine("[2] Load: " + span.TotalSeconds); > > //Execute > d = DateTime.Now; > engine.Execute("getContent(\"http://www.mininova.org\")"); > span = DateTime.Now - d; > System.Console.WriteLine("[3] Execute: " + span.TotalSeconds); > span = DateTime.Now - start; > System.Console.WriteLine("Total: " + span.TotalSeconds); > > > } > } > } > > > On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland < > dinov at exchange.microsoft.com> wrote: > > We've actually had this issue reported once before a long time ago - it's > a very low CodePlex ID - > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 > > We haven't had a chance to investigate the end-to-end scenario. If > someone could come up with a smaller simpler repro that'd be great. > Otherwise we haven't forgotten about it we've just had more immediately > pressing issues to work on :(. > > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto: > users-bounces at lists.ironpython.com] On Behalf Of Michael Foord > Sent: Wednesday, February 20, 2008 5:20 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Slow Performance of CPython libs? > > Birsch wrote: > > Hi - We've been using IronPython successfully to allow extensibility > > of our application. > > > > Overall we are happy with the performance, with the exception of > > BeautifulSoup which seems to run very slowly: x5 or more time to > > execute compared to CPython. > > > > Most of the time seems to be spent during __init__() of BS, where the > > markup is parsed. > > > > We suspect this has to do with the fact that our CPython env is > > executing .pyc files and can precompile its libs, while the IronPython > > environment compiles each iteration. We couldn't find a way to > > pre-compile the libs and then introduce them into the code, but in any > > case this will result in a large management overhead since the amount > > of CPython libs we expose to our users contains 100's of modules. > > > > Any ideas on how to optimize? > > I think it is worth doing real profiling to find out where the time is > being spent during parsing. > > If it is spending most of the time in '__init__' then the time is > probably not spent in importing - so compilation isn't relevant and it > is a runtime performance issue. (Importing is much slower with > IronPython and at Resolver Systems we do use precompiled binaries - but > strangely enough it doesn't provide much of a performance gain.) > > Michael > http://www.manning.com/foord > > > > > Thanks, > > -Birsch > > > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 runtime DLLs > > (this was done to overcome library incompatibilities and network > > errors). However, the relevant slow .py code (mainly SGMLParser and > > BeautifulSoup) is the same. > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dans at houmus.org Thu Feb 21 19:18:49 2008 From: dans at houmus.org (Dan Shechter) Date: Thu, 21 Feb 2008 13:18:49 -0500 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <1e4778de0802211004k6a3fbdf4i79d8de7fd243c6c1@mail.gmail.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> <1e4778de0802210830s60e4f13eue81dd421eca4677@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4EB6CCF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802211004k6a3fbdf4i79d8de7fd243c6c1@mail.gmail.com> Message-ID: <47BDC089.90106@houmus.org> Just out of curiosity... I'm guessing that there are two levels of caching that could be used. One would be to hold a global dictionary of some sort of pattern -> Regex that will save the lengthy parsing of the re. The other would be to actually call Regex.CompileToAssembly to get a more efficient reperesentation (in runtime that is) of the re. Would you (the IP team) favor the former or the latter? Shechter. Birsch wrote: > I checked both sgmllib.py and BeautifulSoup.py - and it seems both are > reusing the same regexps (searched for re.compile). > > I think your suggestion is very relevant in this case. It makes sense to > replicate the "compile once use many" behavior that is commonly used > with regexp. > > -Birsch > > On Thu, Feb 21, 2008 at 7:30 PM, Dino Viehland > > wrote: > > Do you know if the same reg ex is being used repeatedly? If so > maybe we can cache & compile the regex instead of interpretting it > all the time. > > > > *From:* users-bounces at lists.ironpython.com > > [mailto:users-bounces at lists.ironpython.com > ] *On Behalf Of *Birsch > *Sent:* Thursday, February 21, 2008 8:30 AM > > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] Slow Performance of CPython libs? > > > > I took on Cooper's advice and profiled with ANTS. Here are the top > methods: > > *Namespace* > > > > *Method name* > > > > *Time (sec.)* > > > > *Time with children (sec.)* > > > > *Hit count* > > > > *Source file* > > System.Text.RegularExpressions > > > > RegexInterpreter.Go() > > > > 37.0189 > > > > 94.4676 > > > > 13689612 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Operator() > > > > 6.2411 > > > > 6.2411 > > > > 131146274 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Advance(int i) > > > > 5.9264 > > > > 8.7202 > > > > 66000263 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.SetOperator(int op) > > > > 5.5750 > > > > 5.5750 > > > > 131146274 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Backtrack() > > > > 5.5692 > > > > 9.4895 > > > > 37781343 > > > > IronPython.Runtime.Operations > > > > Ops.CallWithContext(ICallerContext context, object func, object > arg0, object arg1) > > > > 5.5572 > > > > 114.5245 > > > > 79754 > > > > IronPython.Runtime.Calls > > > > Method.Call(ICallerContext context, object arg0) > > > > 4.9052 > > > > 114.8251 > > > > 50886 > > > > IronPython.Runtime.Calls > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > object arg1) > > > > 4.8876 > > > > 114.8059 > > > > 50886 > > > > IronPython.Runtime.Calls > > > > Function2.Call(ICallerContext context, object arg0, object arg1) > > > > 4.6400 > > > > 114.5471 > > > > 47486 > > > > IronPython.Runtime.Operations > > > > Ops.CallWithContext(ICallerContext context, object func, object arg0) > > > > 4.2344 > > > > 114.1604 > > > > 146658 > > > > System.Text.RegularExpressions > > > > RegexBoyerMoore.Scan(string text, int index, int beglimit, int endlimit) > > > > 3.6465 > > > > 3.6465 > > > > 13678131 > > > > System.Text.RegularExpressions > > > > RegexCharClass.CharInClassRecursive(char ch, string set, int start) > > > > 3.6288 > > > > 5.7113 > > > > 31508162 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Goto(int newpos) > > > > 3.2058 > > > > 5.1470 > > > > 27364668 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Operand(int i) > > > > 3.1923 > > > > 3.1923 > > > > 73230687 > > > > System.Text.RegularExpressions > > > > RegexRunner.EnsureStorage() > > > > 3.0803 > > > > 3.0803 > > > > 51474823 > > > > System.Text.RegularExpressions > > > > RegexCharClass.CharInClass(char ch, string set) > > > > 3.0713 > > > > 8.7827 > > > > 31508162 > > > > IronPython.Runtime.Calls > > > > Method.Call(ICallerContext context, object arg0, object arg1) > > > > 2.9821 > > > > 7.8675 > > > > 15012 > > > > IronPython.Runtime.Calls > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > object arg1, object arg2) > > > > 2.9794 > > > > 7.8639 > > > > 15012 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Forwardcharnext() > > > > 2.8852 > > > > 2.8852 > > > > 62865185 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Forwardchars() > > > > 2.8279 > > > > 2.8279 > > > > 59436277 > > > > System.Text.RegularExpressions > > > > RegexCharClass.CharInClassInternal(char ch, string set, int start, > int mySetLength, int myCategoryLength) > > > > 2.0632 > > > > 2.0826 > > > > 31508162 > > > > System.Text.RegularExpressions > > > > RegexRunner.Scan(Regex regex, string text, int textbeg, int textend, > int textstart, int prevlen, bool quick) > > > > 1.8376 > > > > 101.7226 > > > > 43009 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.FindFirstChar() > > > > 1.6405 > > > > 5.3456 > > > > 13701755 > > > > IronPython.Runtime.Types > > > > OldClass.TryLookupSlot(SymbolId name, out object ret) > > > > 1.5573 > > > > 2.8124 > > > > 389516 > > > > IronPython.Runtime.Operations > > > > Ops.GetAttr(ICallerContext context, object o, SymbolId name) > > > > 1.5365 > > > > 5.3456 > > > > 558524 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Textpos() > > > > 1.4020 > > > > 1.4020 > > > > 32648926 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Advance() > > > > 1.1916 > > > > 2.9526 > > > > 13703950 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Textto(int newpos) > > > > 1.1218 > > > > 1.1218 > > > > 24120890 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPeek() > > > > 1.0579 > > > > 1.0579 > > > > 24120894 > > > > System.Text.RegularExpressions > > > > Regex.Run(bool quick, int prevlen, string input, int beginning, int > length, int startat) > > > > 0.7280 > > > > 102.4644 > > > > 43009 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPush(int I1) > > > > 0.6834 > > > > 0.6834 > > > > 13745149 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.StackPush(int I1) > > > > 0.6542 > > > > 0.6542 > > > > 13703955 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPop() > > > > 0.6068 > > > > 0.6068 > > > > 13663035 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPush() > > > > 0.6049 > > > > 0.6049 > > > > 13708230 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.StackPop() > > > > 0.5836 > > > > 0.5836 > > > > 13703956 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Bump() > > > > 0.4987 > > > > 0.4987 > > > > 10472790 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPush(int I1, int I2) > > > > 0.4864 > > > > 0.4864 > > > > 10472790 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPeek(int i) > > > > 0.4663 > > > > 0.4663 > > > > 10457859 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPop(int framesize) > > > > 0.4396 > > > > 0.4396 > > > > 10457859 > > > > > Moving up the stack of regex.Go(), most calls originate from > sgmllib's parse_starttag. > > HTH, > -Birsch > > On Thu, Feb 21, 2008 at 2:35 PM, Birsch > wrote: > > Thanks Michael and Dino. > > I'll prof and send update. Got a good profiler recommendation for .Net? > Meanwhile I noticed the sample site below causes BeautifulSoup to > generate quite a few [python] exceptions during __init__. Does > IronPython handle exceptions significantly slower than CPtyhon? > > Repro code is simple (just build a BeautifulSoup obj with mininova's > home page). > Here are the .py and .cs I used to time the diffs: > > *bstest.py:* > #Bypass CPython default socket implementation with IPCE/FePy > import imp, os, sys > sys.modules['socket'] = module = imp.new_module('socket') > execfile('socket.py', module.__dict__) > > from BeautifulSoup import BeautifulSoup > from urllib import urlopen > import datetime > > def getContent(url): > #Download html data > startTime = datetime.datetime.now() > print "Getting url", url > html = urlopen(url).read() > print "Time taken:", datetime.datetime.now() - startTime > > #Make soup > startTime = datetime.datetime.now() > print "Making soup..." > soup = BeautifulSoup(markup=html) > print "Time taken:", datetime.datetime.now() - startTime > > if __name__ == "__main__": > print getContent("www.mininova.org ") > > > *C#:* > using System; > using System.Collections.Generic; > using System.Text; > using IronPython.Hosting; > > namespace IronPythonBeautifulSoupTest > { > public class Program > { > public static void Main(string[] args) > { > //Init > System.Console.WriteLine("Starting..."); > DateTime start = DateTime.Now; > PythonEngine engine = new PythonEngine(); > > //Add paths: > //BeautifulSoup.py, socket.py, bstest.py located on exe dir > engine.AddToPath(@"."); > //CPython Lib (replace with your own) > engine.AddToPath(@"D:\Dev\Python\Lib"); > > //Import and load > TimeSpan span = DateTime.Now - start; > System.Console.WriteLine("[1] Import: " + > span.TotalSeconds); > DateTime d = DateTime.Now; > engine.ExecuteFile(@"bstest.py"); > span = DateTime.Now - d; > System.Console.WriteLine("[2] Load: " + span.TotalSeconds); > > //Execute > d = DateTime.Now; > engine.Execute("getContent(\"http://www.mininova.org\")"); > span = DateTime.Now - d; > System.Console.WriteLine("[3] Execute: " + > span.TotalSeconds); > span = DateTime.Now - start; > System.Console.WriteLine("Total: " + span.TotalSeconds); > > > } > } > } > > > On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland > > > wrote: > > We've actually had this issue reported once before a long time ago - > it's a very low CodePlex ID - > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 > > We haven't had a chance to investigate the end-to-end scenario. If > someone could come up with a smaller simpler repro that'd be great. > Otherwise we haven't forgotten about it we've just had more > immediately pressing issues to work on :(. > > > -----Original Message----- > From: users-bounces at lists.ironpython.com > > [mailto:users-bounces at lists.ironpython.com > ] On Behalf Of Michael Foord > Sent: Wednesday, February 20, 2008 5:20 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Slow Performance of CPython libs? > > Birsch wrote: > > Hi - We've been using IronPython successfully to allow extensibility > > of our application. > > > > Overall we are happy with the performance, with the exception of > > BeautifulSoup which seems to run very slowly: x5 or more time to > > execute compared to CPython. > > > > Most of the time seems to be spent during __init__() of BS, where the > > markup is parsed. > > > > We suspect this has to do with the fact that our CPython env is > > executing .pyc files and can precompile its libs, while the > IronPython > > environment compiles each iteration. We couldn't find a way to > > pre-compile the libs and then introduce them into the code, but > in any > > case this will result in a large management overhead since the amount > > of CPython libs we expose to our users contains 100's of modules. > > > > Any ideas on how to optimize? > > I think it is worth doing real profiling to find out where the time is > being spent during parsing. > > If it is spending most of the time in '__init__' then the time is > probably not spent in importing - so compilation isn't relevant and it > is a runtime performance issue. (Importing is much slower with > IronPython and at Resolver Systems we do use precompiled binaries - but > strangely enough it doesn't provide much of a performance gain.) > > Michael > http://www.manning.com/foord > > > > > Thanks, > > -Birsch > > > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 runtime DLLs > > (this was done to overcome library incompatibilities and network > > errors). However, the relevant slow .py code (mainly SGMLParser and > > BeautifulSoup) is the same. > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From dinov at exchange.microsoft.com Thu Feb 21 19:48:41 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Thu, 21 Feb 2008 10:48:41 -0800 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <47BDC089.90106@houmus.org> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> <1e4778de0802210830s60e4f13eue81dd421eca4677@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4EB6CCF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802211004k6a3fbdf4i79d8de7fd243c6c1@mail.gmail.com> <47BDC089.90106@houmus.org> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4EB6D2B@DF-GRTDANE-MSG.exchange.corp.microsoft.com> After Birsh's last comment that they're calling compile I was thinking we might be doing something really stupid. Turns out that we are. For our supposedly compiled regex's we're not passing the Compiled option. So they're all getting interpretted and of course that's going to suck big time. So the fix for this is probably to just pass RegexOptions.Compiled to the Regex object being contructed into RE_Pattern. Internally the Regex class will compile to dynamic methods (much better than compiling to an assembly because it'll be collectible). It's actually a little more complex than that because we create RE_Pattern objects for the non-compiled so we need to flow the option in, but it's still a simple fix. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dan Shechter Sent: Thursday, February 21, 2008 10:19 AM To: Discussion of IronPython Subject: Re: [IronPython] Slow Performance of CPython libs? Just out of curiosity... I'm guessing that there are two levels of caching that could be used. One would be to hold a global dictionary of some sort of pattern -> Regex that will save the lengthy parsing of the re. The other would be to actually call Regex.CompileToAssembly to get a more efficient reperesentation (in runtime that is) of the re. Would you (the IP team) favor the former or the latter? Shechter. Birsch wrote: > I checked both sgmllib.py and BeautifulSoup.py - and it seems both are > reusing the same regexps (searched for re.compile). > > I think your suggestion is very relevant in this case. It makes sense to > replicate the "compile once use many" behavior that is commonly used > with regexp. > > -Birsch > > On Thu, Feb 21, 2008 at 7:30 PM, Dino Viehland > > wrote: > > Do you know if the same reg ex is being used repeatedly? If so > maybe we can cache & compile the regex instead of interpretting it > all the time. > > > > *From:* users-bounces at lists.ironpython.com > > [mailto:users-bounces at lists.ironpython.com > ] *On Behalf Of *Birsch > *Sent:* Thursday, February 21, 2008 8:30 AM > > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] Slow Performance of CPython libs? > > > > I took on Cooper's advice and profiled with ANTS. Here are the top > methods: > > *Namespace* > > > > *Method name* > > > > *Time (sec.)* > > > > *Time with children (sec.)* > > > > *Hit count* > > > > *Source file* > > System.Text.RegularExpressions > > > > RegexInterpreter.Go() > > > > 37.0189 > > > > 94.4676 > > > > 13689612 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Operator() > > > > 6.2411 > > > > 6.2411 > > > > 131146274 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Advance(int i) > > > > 5.9264 > > > > 8.7202 > > > > 66000263 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.SetOperator(int op) > > > > 5.5750 > > > > 5.5750 > > > > 131146274 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Backtrack() > > > > 5.5692 > > > > 9.4895 > > > > 37781343 > > > > IronPython.Runtime.Operations > > > > Ops.CallWithContext(ICallerContext context, object func, object > arg0, object arg1) > > > > 5.5572 > > > > 114.5245 > > > > 79754 > > > > IronPython.Runtime.Calls > > > > Method.Call(ICallerContext context, object arg0) > > > > 4.9052 > > > > 114.8251 > > > > 50886 > > > > IronPython.Runtime.Calls > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > object arg1) > > > > 4.8876 > > > > 114.8059 > > > > 50886 > > > > IronPython.Runtime.Calls > > > > Function2.Call(ICallerContext context, object arg0, object arg1) > > > > 4.6400 > > > > 114.5471 > > > > 47486 > > > > IronPython.Runtime.Operations > > > > Ops.CallWithContext(ICallerContext context, object func, object arg0) > > > > 4.2344 > > > > 114.1604 > > > > 146658 > > > > System.Text.RegularExpressions > > > > RegexBoyerMoore.Scan(string text, int index, int beglimit, int endlimit) > > > > 3.6465 > > > > 3.6465 > > > > 13678131 > > > > System.Text.RegularExpressions > > > > RegexCharClass.CharInClassRecursive(char ch, string set, int start) > > > > 3.6288 > > > > 5.7113 > > > > 31508162 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Goto(int newpos) > > > > 3.2058 > > > > 5.1470 > > > > 27364668 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Operand(int i) > > > > 3.1923 > > > > 3.1923 > > > > 73230687 > > > > System.Text.RegularExpressions > > > > RegexRunner.EnsureStorage() > > > > 3.0803 > > > > 3.0803 > > > > 51474823 > > > > System.Text.RegularExpressions > > > > RegexCharClass.CharInClass(char ch, string set) > > > > 3.0713 > > > > 8.7827 > > > > 31508162 > > > > IronPython.Runtime.Calls > > > > Method.Call(ICallerContext context, object arg0, object arg1) > > > > 2.9821 > > > > 7.8675 > > > > 15012 > > > > IronPython.Runtime.Calls > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > object arg1, object arg2) > > > > 2.9794 > > > > 7.8639 > > > > 15012 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Forwardcharnext() > > > > 2.8852 > > > > 2.8852 > > > > 62865185 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Forwardchars() > > > > 2.8279 > > > > 2.8279 > > > > 59436277 > > > > System.Text.RegularExpressions > > > > RegexCharClass.CharInClassInternal(char ch, string set, int start, > int mySetLength, int myCategoryLength) > > > > 2.0632 > > > > 2.0826 > > > > 31508162 > > > > System.Text.RegularExpressions > > > > RegexRunner.Scan(Regex regex, string text, int textbeg, int textend, > int textstart, int prevlen, bool quick) > > > > 1.8376 > > > > 101.7226 > > > > 43009 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.FindFirstChar() > > > > 1.6405 > > > > 5.3456 > > > > 13701755 > > > > IronPython.Runtime.Types > > > > OldClass.TryLookupSlot(SymbolId name, out object ret) > > > > 1.5573 > > > > 2.8124 > > > > 389516 > > > > IronPython.Runtime.Operations > > > > Ops.GetAttr(ICallerContext context, object o, SymbolId name) > > > > 1.5365 > > > > 5.3456 > > > > 558524 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Textpos() > > > > 1.4020 > > > > 1.4020 > > > > 32648926 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Advance() > > > > 1.1916 > > > > 2.9526 > > > > 13703950 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Textto(int newpos) > > > > 1.1218 > > > > 1.1218 > > > > 24120890 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPeek() > > > > 1.0579 > > > > 1.0579 > > > > 24120894 > > > > System.Text.RegularExpressions > > > > Regex.Run(bool quick, int prevlen, string input, int beginning, int > length, int startat) > > > > 0.7280 > > > > 102.4644 > > > > 43009 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPush(int I1) > > > > 0.6834 > > > > 0.6834 > > > > 13745149 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.StackPush(int I1) > > > > 0.6542 > > > > 0.6542 > > > > 13703955 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPop() > > > > 0.6068 > > > > 0.6068 > > > > 13663035 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPush() > > > > 0.6049 > > > > 0.6049 > > > > 13708230 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.StackPop() > > > > 0.5836 > > > > 0.5836 > > > > 13703956 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Bump() > > > > 0.4987 > > > > 0.4987 > > > > 10472790 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPush(int I1, int I2) > > > > 0.4864 > > > > 0.4864 > > > > 10472790 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPeek(int i) > > > > 0.4663 > > > > 0.4663 > > > > 10457859 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPop(int framesize) > > > > 0.4396 > > > > 0.4396 > > > > 10457859 > > > > > Moving up the stack of regex.Go(), most calls originate from > sgmllib's parse_starttag. > > HTH, > -Birsch > > On Thu, Feb 21, 2008 at 2:35 PM, Birsch > wrote: > > Thanks Michael and Dino. > > I'll prof and send update. Got a good profiler recommendation for .Net? > Meanwhile I noticed the sample site below causes BeautifulSoup to > generate quite a few [python] exceptions during __init__. Does > IronPython handle exceptions significantly slower than CPtyhon? > > Repro code is simple (just build a BeautifulSoup obj with mininova's > home page). > Here are the .py and .cs I used to time the diffs: > > *bstest.py:* > #Bypass CPython default socket implementation with IPCE/FePy > import imp, os, sys > sys.modules['socket'] = module = imp.new_module('socket') > execfile('socket.py', module.__dict__) > > from BeautifulSoup import BeautifulSoup > from urllib import urlopen > import datetime > > def getContent(url): > #Download html data > startTime = datetime.datetime.now() > print "Getting url", url > html = urlopen(url).read() > print "Time taken:", datetime.datetime.now() - startTime > > #Make soup > startTime = datetime.datetime.now() > print "Making soup..." > soup = BeautifulSoup(markup=html) > print "Time taken:", datetime.datetime.now() - startTime > > if __name__ == "__main__": > print getContent("www.mininova.org ") > > > *C#:* > using System; > using System.Collections.Generic; > using System.Text; > using IronPython.Hosting; > > namespace IronPythonBeautifulSoupTest > { > public class Program > { > public static void Main(string[] args) > { > //Init > System.Console.WriteLine("Starting..."); > DateTime start = DateTime.Now; > PythonEngine engine = new PythonEngine(); > > //Add paths: > //BeautifulSoup.py, socket.py, bstest.py located on exe dir > engine.AddToPath(@"."); > //CPython Lib (replace with your own) > engine.AddToPath(@"D:\Dev\Python\Lib"); > > //Import and load > TimeSpan span = DateTime.Now - start; > System.Console.WriteLine("[1] Import: " + > span.TotalSeconds); > DateTime d = DateTime.Now; > engine.ExecuteFile(@"bstest.py"); > span = DateTime.Now - d; > System.Console.WriteLine("[2] Load: " + span.TotalSeconds); > > //Execute > d = DateTime.Now; > engine.Execute("getContent(\"http://www.mininova.org\")"); > span = DateTime.Now - d; > System.Console.WriteLine("[3] Execute: " + > span.TotalSeconds); > span = DateTime.Now - start; > System.Console.WriteLine("Total: " + span.TotalSeconds); > > > } > } > } > > > On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland > > > wrote: > > We've actually had this issue reported once before a long time ago - > it's a very low CodePlex ID - > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 > > We haven't had a chance to investigate the end-to-end scenario. If > someone could come up with a smaller simpler repro that'd be great. > Otherwise we haven't forgotten about it we've just had more > immediately pressing issues to work on :(. > > > -----Original Message----- > From: users-bounces at lists.ironpython.com > > [mailto:users-bounces at lists.ironpython.com > ] On Behalf Of Michael Foord > Sent: Wednesday, February 20, 2008 5:20 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Slow Performance of CPython libs? > > Birsch wrote: > > Hi - We've been using IronPython successfully to allow extensibility > > of our application. > > > > Overall we are happy with the performance, with the exception of > > BeautifulSoup which seems to run very slowly: x5 or more time to > > execute compared to CPython. > > > > Most of the time seems to be spent during __init__() of BS, where the > > markup is parsed. > > > > We suspect this has to do with the fact that our CPython env is > > executing .pyc files and can precompile its libs, while the > IronPython > > environment compiles each iteration. We couldn't find a way to > > pre-compile the libs and then introduce them into the code, but > in any > > case this will result in a large management overhead since the amount > > of CPython libs we expose to our users contains 100's of modules. > > > > Any ideas on how to optimize? > > I think it is worth doing real profiling to find out where the time is > being spent during parsing. > > If it is spending most of the time in '__init__' then the time is > probably not spent in importing - so compilation isn't relevant and it > is a runtime performance issue. (Importing is much slower with > IronPython and at Resolver Systems we do use precompiled binaries - but > strangely enough it doesn't provide much of a performance gain.) > > Michael > http://www.manning.com/foord > > > > > Thanks, > > -Birsch > > > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 runtime DLLs > > (this was done to overcome library incompatibilities and network > > errors). However, the relevant slow .py code (mainly SGMLParser and > > BeautifulSoup) is the same. > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From Kyle.Howland-Rose at aar.com.au Fri Feb 22 04:37:52 2008 From: Kyle.Howland-Rose at aar.com.au (Howland-Rose, Kyle) Date: Fri, 22 Feb 2008 14:37:52 +1100 Subject: [IronPython] (no subject) Message-ID: <204557C1883DCD40B4F8039D8E3C3B0827E989@SYDEXCVS0.aar.com.au> Hi all, I am following http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET but using VB. In VB I declare a class and derive a python 1.1 class from it but when I return it I get the exception: "Unable to cast object of type 'IronPython.NewTypes.WebControlLibrary.ChildControl_1' to type 'WebControlLibrary.ChildControl'." The page referenced above just seems to cast the python class instance to the C# class instance but this does not work for me in VB. Any help would be appreciated :) Thanks, Kyle ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************* -------------- next part -------------- An HTML attachment was scrubbed... URL: From Kyle.Howland-Rose at aar.com.au Fri Feb 22 04:39:52 2008 From: Kyle.Howland-Rose at aar.com.au (Howland-Rose, Kyle) Date: Fri, 22 Feb 2008 14:39:52 +1100 Subject: [IronPython] returning inherited classes to .NET Message-ID: <204557C1883DCD40B4F8039D8E3C3B0827E98A@SYDEXCVS0.aar.com.au> Again but with subject, sorry :( ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Howland-Rose, Kyle Sent: Friday, 22 February 2008 2:38 PM To: users at lists.ironpython.com Subject: [IronPython] (no subject) Hi all, I am following http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET but using VB. In VB I declare a class and derive a python 1.1 class from it but when I return it I get the exception: "Unable to cast object of type 'IronPython.NewTypes.WebControlLibrary.ChildControl_1' to type 'WebControlLibrary.ChildControl'." The page referenced above just seems to cast the python class instance to the C# class instance but this does not work for me in VB. Any help would be appreciated :) Thanks, Kyle ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************* -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: ATT370721.txt URL: From curt at hagenlocher.org Fri Feb 22 05:08:01 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Thu, 21 Feb 2008 20:08:01 -0800 Subject: [IronPython] returning inherited classes to .NET In-Reply-To: <204557C1883DCD40B4F8039D8E3C3B0827E98A@SYDEXCVS0.aar.com.au> References: <204557C1883DCD40B4F8039D8E3C3B0827E98A@SYDEXCVS0.aar.com.au> Message-ID: The page in question doesn't seem to show what you describe -- deriving a Python class from a C# class. Maybe you could show us your sample code? On Thu, Feb 21, 2008 at 7:39 PM, Howland-Rose, Kyle < Kyle.Howland-Rose at aar.com.au> wrote: > Hi all, > > I am following > http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET but > using VB. > > In VB I declare a class and derive a python 1.1 class from it but when I > return it I get the exception: > > "Unable to cast object of type ' > IronPython.NewTypes.WebControlLibrary.ChildControl_1' to type ' > WebControlLibrary.ChildControl'." > > The page referenced above just seems to cast the python class instance to > the C# class instance but this does not work for me in VB. > > Any help would be appreciated :) > > Thanks, > > Kyle > > > > ************************************************************************ > > Allens Arthur Robinson online: http://www.aar.com.au > > This email is confidential and may be subject to legal or other > professional privilege. It is also subject to copyright. If you have > received it in error, confidentiality and privilege are not waived and you > must not disclose or use the information in it. Please notify the sender by > return email and delete it from your system. Any personal information in > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > ************************************************************************* > > > > ************************************************************************ > > Allens Arthur Robinson online: http://www.aar.com.au > > This email is confidential and may be subject to legal or other > professional privilege. It is also subject to copyright. If you have > received it in error, confidentiality and privilege are not waived and you > must not disclose or use the information in it. Please notify the sender by > return email and delete it from your system. Any personal information in > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > ************************************************************************* > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Kyle.Howland-Rose at aar.com.au Fri Feb 22 05:43:39 2008 From: Kyle.Howland-Rose at aar.com.au (Howland-Rose, Kyle) Date: Fri, 22 Feb 2008 15:43:39 +1100 Subject: [IronPython] FW: returning inherited classes to .NET Message-ID: <204557C1883DCD40B4F8039D8E3C3B0827E98C@SYDEXCVS0.aar.com.au> Hi Curt, Thanks for replying. When I view the link I see the following: The .NET code creates the "Test" class and then runs the python code which imports the "Test" class a subclasses it to create python class "X". Class "X" is then called and cast to type "Test" and assigned to the value obj. Is this what you are looking at? My code is pretty much identical. The VB looks like: Public MustInherit Class ChildControl Public Function Control() As WebControl Return Nothing End Function Public Function GetValue() As String Return Nothing End Function Public Function SetValue(ByVal value As Object) As String Return Nothing End Function End Class Class IPReflection Private Shared Instance As IPReflection = Nothing Private PyEngine As PythonEngine Private PyModule As EngineModule Public Shared Function Inst() As IPReflection If Instance Is Nothing Then Instance = New IPReflection End If Return Instance End Function Private Sub New() Dim path As String = HttpContext.Current.Request.MapPath(".") PyEngine = New PythonEngine PyEngine.AddToPath(path) PyModule = PyEngine.CreateModule PyEngine.DefaultModule = PyModule PyEngine.ExecuteFile(HttpContext.Current.Request.MapPath("CustomControls .py")) End Sub Public Function GetChildControl() As ChildControl Return CType(Operations.Ops.Call(PyModule.Globals("GetControl")), ChildControl) End Function End Class And the python looks like: import clr import sys clr.AddReference('System') import System sys.path.append(sys.path[0] + "/bin") clr.AddReferenceToFile("WebControlLibrary.dll") clr.AddReference('System.Web') from System.Web.UI.WebControls import Label from WebControlLibrary import ChildControl class LabelChildControl(ChildControl): def __init__(self): self.control = Label() def Control(self): return self.control def GetControl(): return LabelChildControl() Thanks again, Kyle ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Friday, 22 February 2008 3:08 PM To: Discussion of IronPython Subject: Re: [IronPython] returning inherited classes to .NET The page in question doesn't seem to show what you describe -- deriving a Python class from a C# class. Maybe you could show us your sample code? On Thu, Feb 21, 2008 at 7:39 PM, Howland-Rose, Kyle wrote: Hi all, I am following http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET but using VB. In VB I declare a class and derive a python 1.1 class from it but when I return it I get the exception: "Unable to cast object of type 'IronPython.NewTypes.WebControlLibrary.ChildControl_1' to type 'WebControlLibrary.ChildControl'." The page referenced above just seems to cast the python class instance to the C# class instance but this does not work for me in VB. Any help would be appreciated :) Thanks, Kyle ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************* -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: ATT376517.txt URL: From curt at hagenlocher.org Fri Feb 22 06:28:46 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Thu, 21 Feb 2008 21:28:46 -0800 Subject: [IronPython] FW: returning inherited classes to .NET In-Reply-To: <204557C1883DCD40B4F8039D8E3C3B0827E98C@SYDEXCVS0.aar.com.au> References: <204557C1883DCD40B4F8039D8E3C3B0827E98C@SYDEXCVS0.aar.com.au> Message-ID: My apologies; I wasn't reading the code correctly. That's probably a sign that I should be going to bed. :) Have you tried simplifying your version just a little bit by running it directly rather than through ASP.NET ? On Thu, Feb 21, 2008 at 8:43 PM, Howland-Rose, Kyle < Kyle.Howland-Rose at aar.com.au> wrote: > Hi Curt, > > Thanks for replying. When I view the link I see the following: > > The .NET code creates the "Test" class and then runs the python code > which imports the "Test" class a subclasses it to create python class > "X". > > Class "X" is then called and cast to type "Test" and assigned to the > value obj. > > Is this what you are looking at? > > My code is pretty much identical. The VB looks like: > > > Public MustInherit Class ChildControl > Public Function Control() As WebControl > Return Nothing > End Function > Public Function GetValue() As String > Return Nothing > End Function > Public Function SetValue(ByVal value As Object) As String > Return Nothing > End Function > End Class > > Class IPReflection > Private Shared Instance As IPReflection = Nothing > Private PyEngine As PythonEngine > Private PyModule As EngineModule > > Public Shared Function Inst() As IPReflection > If Instance Is Nothing Then > Instance = New IPReflection > End If > Return Instance > End Function > > Private Sub New() > Dim path As String = HttpContext.Current.Request.MapPath(".") > PyEngine = New PythonEngine > PyEngine.AddToPath(path) > PyModule = PyEngine.CreateModule > PyEngine.DefaultModule = PyModule > > PyEngine.ExecuteFile(HttpContext.Current.Request.MapPath("CustomControls > .py")) > End Sub > > Public Function GetChildControl() As ChildControl > Return > CType(Operations.Ops.Call(PyModule.Globals("GetControl")), ChildControl) > End Function > End Class > > And the python looks like: > > import clr > import sys > > clr.AddReference('System') > import System > > sys.path.append(sys.path[0] + "/bin") > > clr.AddReferenceToFile("WebControlLibrary.dll") > clr.AddReference('System.Web') > > from System.Web.UI.WebControls import Label > > from WebControlLibrary import ChildControl > > class LabelChildControl(ChildControl): > def __init__(self): > self.control = Label() > def Control(self): > return self.control > > def GetControl(): > return LabelChildControl() > > > Thanks again, > Kyle > > ________________________________ > > From: users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt > Hagenlocher > Sent: Friday, 22 February 2008 3:08 PM > To: Discussion of IronPython > Subject: Re: [IronPython] returning inherited classes to .NET > > > The page in question doesn't seem to show what you describe -- deriving > a Python class from a C# class. Maybe you could show us your sample > code? > > > On Thu, Feb 21, 2008 at 7:39 PM, Howland-Rose, Kyle > wrote: > > > Hi all, > I am following > > > http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET > > but using VB. > > In VB I declare a class and derive a python 1.1 class from it > but when I return it I get the exception: > > "Unable to cast object of type > 'IronPython.NewTypes.WebControlLibrary.ChildControl_1' to type > 'WebControlLibrary.ChildControl'." > > The page referenced above just seems to cast the python class > instance to the C# class instance but this does not work for me in VB. > > Any help would be appreciated :) > > Thanks, > > Kyle > > > > > ************************************************************************ > > Allens Arthur Robinson online: http://www.aar.com.au > > > This email is confidential and may be subject to legal or other > professional privilege. It is also subject to copyright. If you have > received it in error, confidentiality and privilege are not waived and > you must not disclose or use the information in it. Please notify the > sender by return email and delete it from your system. Any personal > information in this email must be handled in accordance with the Privacy > Act 1988 (Cth). > > > ************************************************************************ > * > > > > > ************************************************************************ > > Allens Arthur Robinson online: http://www.aar.com.au > > > This email is confidential and may be subject to legal or other > professional privilege. It is also subject to copyright. If you have > received it in error, confidentiality and privilege are not waived and > you must not disclose or use the information in it. Please notify the > sender by return email and delete it from your system. Any personal > information in this email must be handled in accordance with the Privacy > Act 1988 (Cth). > > > ************************************************************************ > * > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > ************************************************************************ > > Allens Arthur Robinson online: http://www.aar.com.au > > This email is confidential and may be subject to legal or other > professional privilege. It is also subject to copyright. If you have > received it in error, confidentiality and privilege are not waived and you > must not disclose or use the information in it. Please notify the sender by > return email and delete it from your system. Any personal information in > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > ************************************************************************* > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Kyle.Howland-Rose at aar.com.au Fri Feb 22 06:44:34 2008 From: Kyle.Howland-Rose at aar.com.au (Howland-Rose, Kyle) Date: Fri, 22 Feb 2008 16:44:34 +1100 Subject: [IronPython] FW: FW: returning inherited classes to .NET Message-ID: <204557C1883DCD40B4F8039D8E3C3B0827E98D@SYDEXCVS0.aar.com.au> It runs fine from the command line but then it does not do much ... yet. For the moment I am simplifying it by removing IP :( I wanted to so some moderately heavy reflection which to my thinking should be easier from IP but I will use VB for now. I assume I *should* be able to return a derived python class to VB? Alternatively I could implement an interface. How can IP implement a .NET interface? (All pointers to pre-existing doco warmly received :) Thanks Kyle ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Friday, 22 February 2008 4:29 PM To: Discussion of IronPython Subject: Re: [IronPython] FW: returning inherited classes to .NET My apologies; I wasn't reading the code correctly. That's probably a sign that I should be going to bed. :) Have you tried simplifying your version just a little bit by running it directly rather than through ASP.NET ? On Thu, Feb 21, 2008 at 8:43 PM, Howland-Rose, Kyle < Kyle.Howland-Rose at aar.com.au> wrote: Hi Curt, Thanks for replying. When I view the link I see the following: The .NET code creates the "Test" class and then runs the python code which imports the "Test" class a subclasses it to create python class "X". Class "X" is then called and cast to type "Test" and assigned to the value obj. Is this what you are looking at? My code is pretty much identical. The VB looks like: Public MustInherit Class ChildControl Public Function Control() As WebControl Return Nothing End Function Public Function GetValue() As String Return Nothing End Function Public Function SetValue(ByVal value As Object) As String Return Nothing End Function End Class Class IPReflection Private Shared Instance As IPReflection = Nothing Private PyEngine As PythonEngine Private PyModule As EngineModule Public Shared Function Inst() As IPReflection If Instance Is Nothing Then Instance = New IPReflection End If Return Instance End Function Private Sub New() Dim path As String = HttpContext.Current.Request.MapPath(".") PyEngine = New PythonEngine PyEngine.AddToPath(path) PyModule = PyEngine.CreateModule PyEngine.DefaultModule = PyModule PyEngine.ExecuteFile(HttpContext.Current.Request.MapPath("CustomControls .py")) End Sub Public Function GetChildControl() As ChildControl Return CType(Operations.Ops.Call(PyModule.Globals("GetControl")), ChildControl) End Function End Class And the python looks like: import clr import sys clr.AddReference('System') import System sys.path.append(sys.path[0] + "/bin") clr.AddReferenceToFile("WebControlLibrary.dll") clr.AddReference('System.Web') from System.Web.UI.WebControls import Label from WebControlLibrary import ChildControl class LabelChildControl(ChildControl): def __init__(self): self.control = Label() def Control(self): return self.control def GetControl(): return LabelChildControl() Thanks again, Kyle ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Friday, 22 February 2008 3:08 PM To: Discussion of IronPython Subject: Re: [IronPython] returning inherited classes to .NET The page in question doesn't seem to show what you describe -- deriving a Python class from a C# class. Maybe you could show us your sample code? On Thu, Feb 21, 2008 at 7:39 PM, Howland-Rose, Kyle wrote: Hi all, I am following http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET < http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET> but using VB. In VB I declare a class and derive a python 1.1 class from it but when I return it I get the exception: "Unable to cast object of type 'IronPython.NewTypes.WebControlLibrary.ChildControl_1' to type 'WebControlLibrary.ChildControl'." The page referenced above just seems to cast the python class instance to the C# class instance but this does not work for me in VB. Any help would be appreciated :) Thanks, Kyle ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************* -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: ATT386538.txt URL: From curt at hagenlocher.org Fri Feb 22 06:55:21 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Thu, 21 Feb 2008 21:55:21 -0800 Subject: [IronPython] FW: FW: returning inherited classes to .NET In-Reply-To: <204557C1883DCD40B4F8039D8E3C3B0827E98D@SYDEXCVS0.aar.com.au> References: <204557C1883DCD40B4F8039D8E3C3B0827E98D@SYDEXCVS0.aar.com.au> Message-ID: If you're only getting the error under ASP.NET, then it's highly likely that you're loading multiple copies of the same assembly, which is why the CLR can't cast your Python class back to the VB base -- it literally considers them to be two different classes. This may be related to the way ASP.NETmakes shadow copies of your files, but there could be other reasons as well (none of which, unfortunately, come to mind right now). Using an interface instead of a base class would give you the same results. On Thu, Feb 21, 2008 at 9:44 PM, Howland-Rose, Kyle < Kyle.Howland-Rose at aar.com.au> wrote: > It runs fine from the command line but then it does not do much ... yet. > For the moment I am simplifying it by removing IP :( > > I wanted to so some moderately heavy reflection which to my thinking > should be easier from IP but I will use VB for now. > > I assume I *should* be able to return a derived python class to VB? > Alternatively I could implement an interface. How can IP implement a .NET > interface? > (All pointers to pre-existing doco warmly received :) > > Thanks > Kyle > > ------------------------------ > *From:* users-bounces at lists.ironpython.com [mailto: > users-bounces at lists.ironpython.com] *On Behalf Of *Curt Hagenlocher > *Sent:* Friday, 22 February 2008 4:29 PM > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] FW: returning inherited classes to .NET > > My apologies; I wasn't reading the code correctly. That's probably a > sign that I should be going to bed. :) Have you tried simplifying your > version just a little bit by running it directly rather than through > ASP.NET ? > > > On Thu, Feb 21, 2008 at 8:43 PM, Howland-Rose, Kyle < > Kyle.Howland-Rose at aar.com.au> wrote: > > > Hi Curt, > > > > Thanks for replying. When I view the link I see the following: > > > > The .NET code creates the "Test" class and then runs the python code > > which imports the "Test" class a subclasses it to create python class > > "X". > > > > Class "X" is then called and cast to type "Test" and assigned to the > > value obj. > > > > Is this what you are looking at? > > > > My code is pretty much identical. The VB looks like: > > > > > > Public MustInherit Class ChildControl > > Public Function Control() As WebControl > > Return Nothing > > End Function > > Public Function GetValue() As String > > Return Nothing > > End Function > > Public Function SetValue(ByVal value As Object) As String > > Return Nothing > > End Function > > End Class > > > > Class IPReflection > > Private Shared Instance As IPReflection = Nothing > > Private PyEngine As PythonEngine > > Private PyModule As EngineModule > > > > Public Shared Function Inst() As IPReflection > > If Instance Is Nothing Then > > Instance = New IPReflection > > End If > > Return Instance > > End Function > > > > Private Sub New() > > Dim path As String = HttpContext.Current.Request.MapPath(".") > > PyEngine = New PythonEngine > > PyEngine.AddToPath(path) > > PyModule = PyEngine.CreateModule > > PyEngine.DefaultModule = PyModule > > > > PyEngine.ExecuteFile(HttpContext.Current.Request.MapPath("CustomControls > > .py")) > > End Sub > > > > Public Function GetChildControl() As ChildControl > > Return > > CType(Operations.Ops.Call(PyModule.Globals("GetControl")), ChildControl) > > End Function > > End Class > > > > And the python looks like: > > > > import clr > > import sys > > > > clr.AddReference('System') > > import System > > > > sys.path.append(sys.path[0] + "/bin") > > > > clr.AddReferenceToFile("WebControlLibrary.dll") > > clr.AddReference('System.Web') > > > > from System.Web.UI.WebControls import Label > > > > from WebControlLibrary import ChildControl > > > > class LabelChildControl(ChildControl): > > def __init__(self): > > self.control = Label() > > def Control(self): > > return self.control > > > > def GetControl(): > > return LabelChildControl() > > > > > > Thanks again, > > Kyle > > > > ________________________________ > > > > From: users-bounces at lists.ironpython.com > > [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt > > Hagenlocher > > Sent: Friday, 22 February 2008 3:08 PM > > To: Discussion of IronPython > > Subject: Re: [IronPython] returning inherited classes to .NET > > > > > > The page in question doesn't seem to show what you describe -- deriving > > a Python class from a C# class. Maybe you could show us your sample > > code? > > > > > > On Thu, Feb 21, 2008 at 7:39 PM, Howland-Rose, Kyle > > wrote: > > > > > > Hi all, > > I am following > > > > > > http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET > > > > but using VB. > > > > In VB I declare a class and derive a python 1.1 class from it > > but when I return it I get the exception: > > > > "Unable to cast object of type > > 'IronPython.NewTypes.WebControlLibrary.ChildControl_1' to type > > 'WebControlLibrary.ChildControl'." > > > > The page referenced above just seems to cast the python class > > instance to the C# class instance but this does not work for me in VB. > > > > Any help would be appreciated :) > > > > Thanks, > > > > Kyle > > > > > > > > > > ************************************************************************ > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > This email is confidential and may be subject to legal or other > > professional privilege. It is also subject to copyright. If you have > > received it in error, confidentiality and privilege are not waived and > > you must not disclose or use the information in it. Please notify the > > sender by return email and delete it from your system. Any personal > > information in this email must be handled in accordance with the Privacy > > Act 1988 (Cth). > > > > > > ************************************************************************ > > * > > > > > > > > > > ************************************************************************ > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > This email is confidential and may be subject to legal or other > > professional privilege. It is also subject to copyright. If you have > > received it in error, confidentiality and privilege are not waived and > > you must not disclose or use the information in it. Please notify the > > sender by return email and delete it from your system. Any personal > > information in this email must be handled in accordance with the Privacy > > Act 1988 (Cth). > > > > > > ************************************************************************ > > * > > > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > ************************************************************************ > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > This email is confidential and may be subject to legal or other > > professional privilege. It is also subject to copyright. If you have > > received it in error, confidentiality and privilege are not waived and you > > must not disclose or use the information in it. Please notify the sender by > > return email and delete it from your system. Any personal information in > > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > > > > > ************************************************************************* > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > ************************************************************************ > > Allens Arthur Robinson online: http://www.aar.com.au > > This email is confidential and may be subject to legal or other > professional privilege. It is also subject to copyright. If you have > received it in error, confidentiality and privilege are not waived and you > must not disclose or use the information in it. Please notify the sender by > return email and delete it from your system. Any personal information in > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > ************************************************************************* > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Kyle.Howland-Rose at aar.com.au Fri Feb 22 07:07:09 2008 From: Kyle.Howland-Rose at aar.com.au (Howland-Rose, Kyle) Date: Fri, 22 Feb 2008 17:07:09 +1100 Subject: [IronPython] FW: FW: FW: returning inherited classes to .NET Message-ID: <204557C1883DCD40B4F8039D8E3C3B0827E98E@SYDEXCVS0.aar.com.au> Thanks for your help so late Curt (not that I need a quick answer at all). I am sure I am missing something big-time here and "talking" as cross-purposes, but, to my mind the reason I don't have a problem when running from the command line is because all I am doing is running the ipy.exe on the file which loads some assemblies, creates a class definition and a function definition and then terminates without even instantiating the class. Is this what you mean by "running it directly"? Thanks again, Kyle ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Friday, 22 February 2008 4:55 PM To: Discussion of IronPython Subject: Re: [IronPython] FW: FW: returning inherited classes to .NET If you're only getting the error under ASP.NET, then it's highly likely that you're loading multiple copies of the same assembly, which is why the CLR can't cast your Python class back to the VB base -- it literally considers them to be two different classes. This may be related to the way ASP.NET makes shadow copies of your files, but there could be other reasons as well (none of which, unfortunately, come to mind right now). Using an interface instead of a base class would give you the same results. On Thu, Feb 21, 2008 at 9:44 PM, Howland-Rose, Kyle < Kyle.Howland-Rose at aar.com.au> wrote: It runs fine from the command line but then it does not do much ... yet. For the moment I am simplifying it by removing IP :( I wanted to so some moderately heavy reflection which to my thinking should be easier from IP but I will use VB for now. I assume I *should* be able to return a derived python class to VB? Alternatively I could implement an interface. How can IP implement a .NET interface? (All pointers to pre-existing doco warmly received :) Thanks Kyle ________________________________ From: users-bounces at lists.ironpython.com [mailto: users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Friday, 22 February 2008 4:29 PM To: Discussion of IronPython Subject: Re: [IronPython] FW: returning inherited classes to .NET My apologies; I wasn't reading the code correctly. That's probably a sign that I should be going to bed. :) Have you tried simplifying your version just a little bit by running it directly rather than through ASP.NET ? On Thu, Feb 21, 2008 at 8:43 PM, Howland-Rose, Kyle < Kyle.Howland-Rose at aar.com.au> wrote: Hi Curt, Thanks for replying. When I view the link I see the following: The .NET code creates the "Test" class and then runs the python code which imports the "Test" class a subclasses it to create python class "X". Class "X" is then called and cast to type "Test" and assigned to the value obj. Is this what you are looking at? My code is pretty much identical. The VB looks like: Public MustInherit Class ChildControl Public Function Control() As WebControl Return Nothing End Function Public Function GetValue() As String Return Nothing End Function Public Function SetValue(ByVal value As Object) As String Return Nothing End Function End Class Class IPReflection Private Shared Instance As IPReflection = Nothing Private PyEngine As PythonEngine Private PyModule As EngineModule Public Shared Function Inst() As IPReflection If Instance Is Nothing Then Instance = New IPReflection End If Return Instance End Function Private Sub New() Dim path As String = HttpContext.Current.Request.MapPath(".") PyEngine = New PythonEngine PyEngine.AddToPath(path) PyModule = PyEngine.CreateModule PyEngine.DefaultModule = PyModule PyEngine.ExecuteFile(HttpContext.Current.Request.MapPath("CustomControls .py")) End Sub Public Function GetChildControl() As ChildControl Return CType(Operations.Ops.Call(PyModule.Globals("GetControl")), ChildControl) End Function End Class And the python looks like: import clr import sys clr.AddReference('System') import System sys.path.append(sys.path[0] + "/bin") clr.AddReferenceToFile("WebControlLibrary.dll") clr.AddReference('System.Web') from System.Web.UI.WebControls import Label from WebControlLibrary import ChildControl class LabelChildControl(ChildControl): def __init__(self): self.control = Label() def Control(self): return self.control def GetControl(): return LabelChildControl() Thanks again, Kyle ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Friday, 22 February 2008 3:08 PM To: Discussion of IronPython Subject: Re: [IronPython] returning inherited classes to .NET The page in question doesn't seem to show what you describe -- deriving a Python class from a C# class. Maybe you could show us your sample code? On Thu, Feb 21, 2008 at 7:39 PM, Howland-Rose, Kyle wrote: Hi all, I am following http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET < http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET> but using VB. In VB I declare a class and derive a python 1.1 class from it but when I return it I get the exception: "Unable to cast object of type 'IronPython.NewTypes.WebControlLibrary.ChildControl_1' to type 'WebControlLibrary.ChildControl'." The page referenced above just seems to cast the python class instance to the C# class instance but this does not work for me in VB. Any help would be appreciated :) Thanks, Kyle ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************* -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: ATT388781.txt URL: From curt at hagenlocher.org Fri Feb 22 15:02:26 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Fri, 22 Feb 2008 06:02:26 -0800 Subject: [IronPython] FW: FW: FW: returning inherited classes to .NET In-Reply-To: <204557C1883DCD40B4F8039D8E3C3B0827E98E@SYDEXCVS0.aar.com.au> References: <204557C1883DCD40B4F8039D8E3C3B0827E98E@SYDEXCVS0.aar.com.au> Message-ID: Ah, no. I was thinking that you would modify your VB code to launch it as a console app (for instance) rather than from inside of ASP.NET -- and see if you still get the same error. On Thu, Feb 21, 2008 at 10:07 PM, Howland-Rose, Kyle < Kyle.Howland-Rose at aar.com.au> wrote: > Thanks for your help so late Curt (not that I need a quick answer at > all). > > I am sure I am missing something big-time here and "talking" as > cross-purposes, but, to my mind the reason I don't have a problem when > running from the command line is because all I am doing is running the > ipy.exe on the file which loads some assemblies, creates a class > definition and a function definition and then terminates without even > instantiating the class. Is this what you mean by "running it directly"? > > > Thanks again, > Kyle > > ------------------------------ > *From:* users-bounces at lists.ironpython.com [mailto: > users-bounces at lists.ironpython.com] *On Behalf Of *Curt Hagenlocher > *Sent:* Friday, 22 February 2008 4:55 PM > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] FW: FW: returning inherited classes to .NET > > If you're only getting the error under ASP.NET , then > it's highly likely that you're loading multiple copies of the same assembly, > which is why the CLR can't cast your Python class back to the VB base -- it > literally considers them to be two different classes. This may be related > to the way ASP.NET makes shadow copies of your files, > but there could be other reasons as well (none of which, unfortunately, come > to mind right now). > > Using an interface instead of a base class would give you the same > results. > On Thu, Feb 21, 2008 at 9:44 PM, Howland-Rose, Kyle < > Kyle.Howland-Rose at aar.com.au> wrote: > > > It runs fine from the command line but then it does not do much ... > > yet. For the moment I am simplifying it by removing IP :( > > > > I wanted to so some moderately heavy reflection which to my thinking > > should be easier from IP but I will use VB for now. > > > > I assume I *should* be able to return a derived python class to VB? > > Alternatively I could implement an interface. How can IP implement a .NET > > interface? > > (All pointers to pre-existing doco warmly received :) > > > > Thanks > > Kyle > > > > ------------------------------ > > *From:* users-bounces at lists.ironpython.com [mailto: > > users-bounces at lists.ironpython.com] *On Behalf Of *Curt Hagenlocher > > *Sent:* Friday, 22 February 2008 4:29 PM > > *To:* Discussion of IronPython > > *Subject:* Re: [IronPython] FW: returning inherited classes to .NET > > > > My apologies; I wasn't reading the code correctly. That's probably a > > sign that I should be going to bed. :) Have you tried simplifying your > > version just a little bit by running it directly rather than through > > ASP.NET ? > > > > > > On Thu, Feb 21, 2008 at 8:43 PM, Howland-Rose, Kyle < > > Kyle.Howland-Rose at aar.com.au> wrote: > > > > > Hi Curt, > > > > > > Thanks for replying. When I view the link I see the following: > > > > > > The .NET code creates the "Test" class and then runs the python code > > > which imports the "Test" class a subclasses it to create python class > > > "X". > > > > > > Class "X" is then called and cast to type "Test" and assigned to the > > > value obj. > > > > > > Is this what you are looking at? > > > > > > My code is pretty much identical. The VB looks like: > > > > > > > > > Public MustInherit Class ChildControl > > > Public Function Control() As WebControl > > > Return Nothing > > > End Function > > > Public Function GetValue() As String > > > Return Nothing > > > End Function > > > Public Function SetValue(ByVal value As Object) As String > > > Return Nothing > > > End Function > > > End Class > > > > > > Class IPReflection > > > Private Shared Instance As IPReflection = Nothing > > > Private PyEngine As PythonEngine > > > Private PyModule As EngineModule > > > > > > Public Shared Function Inst() As IPReflection > > > If Instance Is Nothing Then > > > Instance = New IPReflection > > > End If > > > Return Instance > > > End Function > > > > > > Private Sub New() > > > Dim path As String = HttpContext.Current.Request.MapPath(".") > > > PyEngine = New PythonEngine > > > PyEngine.AddToPath(path) > > > PyModule = PyEngine.CreateModule > > > PyEngine.DefaultModule = PyModule > > > > > > PyEngine.ExecuteFile(HttpContext.Current.Request.MapPath > > > ("CustomControls > > > .py")) > > > End Sub > > > > > > Public Function GetChildControl() As ChildControl > > > Return > > > CType(Operations.Ops.Call(PyModule.Globals("GetControl")), > > > ChildControl) > > > End Function > > > End Class > > > > > > And the python looks like: > > > > > > import clr > > > import sys > > > > > > clr.AddReference('System') > > > import System > > > > > > sys.path.append(sys.path[0] + "/bin") > > > > > > clr.AddReferenceToFile("WebControlLibrary.dll") > > > clr.AddReference('System.Web') > > > > > > from System.Web.UI.WebControls import Label > > > > > > from WebControlLibrary import ChildControl > > > > > > class LabelChildControl(ChildControl): > > > def __init__(self): > > > self.control = Label() > > > def Control(self): > > > return self.control > > > > > > def GetControl(): > > > return LabelChildControl() > > > > > > > > > Thanks again, > > > Kyle > > > > > > ________________________________ > > > > > > From: users-bounces at lists.ironpython.com > > > [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt > > > Hagenlocher > > > Sent: Friday, 22 February 2008 3:08 PM > > > To: Discussion of IronPython > > > Subject: Re: [IronPython] returning inherited classes to .NET > > > > > > > > > The page in question doesn't seem to show what you describe -- > > > deriving > > > a Python class from a C# class. Maybe you could show us your sample > > > code? > > > > > > > > > On Thu, Feb 21, 2008 at 7:39 PM, Howland-Rose, Kyle > > > wrote: > > > > > > > > > Hi all, > > > I am following > > > > > > > > > http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET > > > > > > but using VB. > > > > > > In VB I declare a class and derive a python 1.1 class from it > > > but when I return it I get the exception: > > > > > > "Unable to cast object of type > > > 'IronPython.NewTypes.WebControlLibrary.ChildControl_1' to type > > > 'WebControlLibrary.ChildControl'." > > > > > > The page referenced above just seems to cast the python class > > > instance to the C# class instance but this does not work for me in VB. > > > > > > Any help would be appreciated :) > > > > > > Thanks, > > > > > > Kyle > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > > > > This email is confidential and may be subject to legal or other > > > professional privilege. It is also subject to copyright. If you have > > > received it in error, confidentiality and privilege are not waived and > > > you must not disclose or use the information in it. Please notify the > > > sender by return email and delete it from your system. Any personal > > > information in this email must be handled in accordance with the > > > Privacy > > > Act 1988 (Cth). > > > > > > > > > > > > ************************************************************************ > > > * > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > > > > This email is confidential and may be subject to legal or other > > > professional privilege. It is also subject to copyright. If you have > > > received it in error, confidentiality and privilege are not waived and > > > you must not disclose or use the information in it. Please notify the > > > sender by return email and delete it from your system. Any personal > > > information in this email must be handled in accordance with the > > > Privacy > > > Act 1988 (Cth). > > > > > > > > > > > > ************************************************************************ > > > * > > > > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > This email is confidential and may be subject to legal or other > > > professional privilege. It is also subject to copyright. If you have > > > received it in error, confidentiality and privilege are not waived and you > > > must not disclose or use the information in it. Please notify the sender by > > > return email and delete it from your system. Any personal information in > > > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > > > > > > > > ************************************************************************* > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > ************************************************************************ > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > This email is confidential and may be subject to legal or other > > professional privilege. It is also subject to copyright. If you have > > received it in error, confidentiality and privilege are not waived and you > > must not disclose or use the information in it. Please notify the sender by > > return email and delete it from your system. Any personal information in > > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > > > > > ************************************************************************* > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > ************************************************************************ > > Allens Arthur Robinson online: http://www.aar.com.au > > This email is confidential and may be subject to legal or other > professional privilege. It is also subject to copyright. If you have > received it in error, confidentiality and privilege are not waived and you > must not disclose or use the information in it. Please notify the sender by > return email and delete it from your system. Any personal information in > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > ************************************************************************* > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From curt at hagenlocher.org Fri Feb 22 15:33:16 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Fri, 22 Feb 2008 06:33:16 -0800 Subject: [IronPython] FW: FW: FW: returning inherited classes to .NET In-Reply-To: References: <204557C1883DCD40B4F8039D8E3C3B0827E98E@SYDEXCVS0.aar.com.au> Message-ID: I built a test executable and was able to reproduce this. And when I changed clr.AddReferenceToFile("WebControlLibrary.dll") to clr.AddReference("WebControlLibrary") it worked as expected. On Fri, Feb 22, 2008 at 6:02 AM, Curt Hagenlocher wrote: > Ah, no. I was thinking that you would modify your VB code to launch it as > a console app (for instance) rather than from inside of ASP.NET-- and see if you still get the same error. > > > On Thu, Feb 21, 2008 at 10:07 PM, Howland-Rose, Kyle < > Kyle.Howland-Rose at aar.com.au> wrote: > > > Thanks for your help so late Curt (not that I need a quick answer at > > all). > > > > I am sure I am missing something big-time here and "talking" as > > cross-purposes, but, to my mind the reason I don't have a problem when > > running from the command line is because all I am doing is running the > > ipy.exe on the file which loads some assemblies, creates a class > > definition and a function definition and then terminates without even > > instantiating the class. Is this what you mean by "running it > > directly"? > > > > Thanks again, > > Kyle > > > > ------------------------------ > > *From:* users-bounces at lists.ironpython.com [mailto: > > users-bounces at lists.ironpython.com] *On Behalf Of *Curt Hagenlocher > > *Sent:* Friday, 22 February 2008 4:55 PM > > *To:* Discussion of IronPython > > *Subject:* Re: [IronPython] FW: FW: returning inherited classes to .NET > > > > If you're only getting the error under ASP.NET , then > > it's highly likely that you're loading multiple copies of the same assembly, > > which is why the CLR can't cast your Python class back to the VB base -- it > > literally considers them to be two different classes. This may be related > > to the way ASP.NET makes shadow copies of your files, > > but there could be other reasons as well (none of which, unfortunately, come > > to mind right now). > > > > Using an interface instead of a base class would give you the same > > results. > > On Thu, Feb 21, 2008 at 9:44 PM, Howland-Rose, Kyle < > > Kyle.Howland-Rose at aar.com.au> wrote: > > > > > It runs fine from the command line but then it does not do much ... > > > yet. For the moment I am simplifying it by removing IP :( > > > > > > I wanted to so some moderately heavy reflection which to my thinking > > > should be easier from IP but I will use VB for now. > > > > > > I assume I *should* be able to return a derived python class to VB? > > > Alternatively I could implement an interface. How can IP implement a .NET > > > interface? > > > (All pointers to pre-existing doco warmly received :) > > > > > > Thanks > > > Kyle > > > > > > ------------------------------ > > > *From:* users-bounces at lists.ironpython.com [mailto: > > > users-bounces at lists.ironpython.com] *On Behalf Of *Curt Hagenlocher > > > *Sent:* Friday, 22 February 2008 4:29 PM > > > *To:* Discussion of IronPython > > > *Subject:* Re: [IronPython] FW: returning inherited classes to .NET > > > > > > My apologies; I wasn't reading the code correctly. That's probably > > > a sign that I should be going to bed. :) Have you tried simplifying your > > > version just a little bit by running it directly rather than through > > > ASP.NET ? > > > > > > > > > On Thu, Feb 21, 2008 at 8:43 PM, Howland-Rose, Kyle < > > > Kyle.Howland-Rose at aar.com.au> wrote: > > > > > > > Hi Curt, > > > > > > > > Thanks for replying. When I view the link I see the following: > > > > > > > > The .NET code creates the "Test" class and then runs the python code > > > > which imports the "Test" class a subclasses it to create python > > > > class > > > > "X". > > > > > > > > Class "X" is then called and cast to type "Test" and assigned to the > > > > value obj. > > > > > > > > Is this what you are looking at? > > > > > > > > My code is pretty much identical. The VB looks like: > > > > > > > > > > > > Public MustInherit Class ChildControl > > > > Public Function Control() As WebControl > > > > Return Nothing > > > > End Function > > > > Public Function GetValue() As String > > > > Return Nothing > > > > End Function > > > > Public Function SetValue(ByVal value As Object) As String > > > > Return Nothing > > > > End Function > > > > End Class > > > > > > > > Class IPReflection > > > > Private Shared Instance As IPReflection = Nothing > > > > Private PyEngine As PythonEngine > > > > Private PyModule As EngineModule > > > > > > > > Public Shared Function Inst() As IPReflection > > > > If Instance Is Nothing Then > > > > Instance = New IPReflection > > > > End If > > > > Return Instance > > > > End Function > > > > > > > > Private Sub New() > > > > Dim path As String = HttpContext.Current.Request.MapPath(".") > > > > PyEngine = New PythonEngine > > > > PyEngine.AddToPath(path) > > > > PyModule = PyEngine.CreateModule > > > > PyEngine.DefaultModule = PyModule > > > > > > > > PyEngine.ExecuteFile(HttpContext.Current.Request.MapPath > > > > ("CustomControls > > > > .py")) > > > > End Sub > > > > > > > > Public Function GetChildControl() As ChildControl > > > > Return > > > > CType(Operations.Ops.Call(PyModule.Globals("GetControl")), > > > > ChildControl) > > > > End Function > > > > End Class > > > > > > > > And the python looks like: > > > > > > > > import clr > > > > import sys > > > > > > > > clr.AddReference('System') > > > > import System > > > > > > > > sys.path.append(sys.path[0] + "/bin") > > > > > > > > clr.AddReferenceToFile("WebControlLibrary.dll") > > > > clr.AddReference('System.Web') > > > > > > > > from System.Web.UI.WebControls import Label > > > > > > > > from WebControlLibrary import ChildControl > > > > > > > > class LabelChildControl(ChildControl): > > > > def __init__(self): > > > > self.control = Label() > > > > def Control(self): > > > > return self.control > > > > > > > > def GetControl(): > > > > return LabelChildControl() > > > > > > > > > > > > Thanks again, > > > > Kyle > > > > > > > > ________________________________ > > > > > > > > From: users-bounces at lists.ironpython.com > > > > [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt > > > > Hagenlocher > > > > Sent: Friday, 22 February 2008 3:08 PM > > > > To: Discussion of IronPython > > > > Subject: Re: [IronPython] returning inherited classes to .NET > > > > > > > > > > > > The page in question doesn't seem to show what you describe -- > > > > deriving > > > > a Python class from a C# class. Maybe you could show us your sample > > > > code? > > > > > > > > > > > > On Thu, Feb 21, 2008 at 7:39 PM, Howland-Rose, Kyle > > > > wrote: > > > > > > > > > > > > Hi all, > > > > I am following > > > > > > > > > > > > http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET > > > > > > > > > > > > but using VB. > > > > > > > > In VB I declare a class and derive a python 1.1 class from it > > > > but when I return it I get the exception: > > > > > > > > "Unable to cast object of type > > > > 'IronPython.NewTypes.WebControlLibrary.ChildControl_1' to type > > > > 'WebControlLibrary.ChildControl'." > > > > > > > > The page referenced above just seems to cast the python class > > > > instance to the C# class instance but this does not work for me in > > > > VB. > > > > > > > > Any help would be appreciated :) > > > > > > > > Thanks, > > > > > > > > Kyle > > > > > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > > > > > > > This email is confidential and may be subject to legal or > > > > other > > > > professional privilege. It is also subject to copyright. If you have > > > > received it in error, confidentiality and privilege are not waived > > > > and > > > > you must not disclose or use the information in it. Please notify > > > > the > > > > sender by return email and delete it from your system. Any personal > > > > information in this email must be handled in accordance with the > > > > Privacy > > > > Act 1988 (Cth). > > > > > > > > > > > > > > > > ************************************************************************ > > > > * > > > > > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > > > > > > > This email is confidential and may be subject to legal or > > > > other > > > > professional privilege. It is also subject to copyright. If you have > > > > received it in error, confidentiality and privilege are not waived > > > > and > > > > you must not disclose or use the information in it. Please notify > > > > the > > > > sender by return email and delete it from your system. Any personal > > > > information in this email must be handled in accordance with the > > > > Privacy > > > > Act 1988 (Cth). > > > > > > > > > > > > > > > > ************************************************************************ > > > > * > > > > > > > > > > > > _______________________________________________ > > > > Users mailing list > > > > Users at lists.ironpython.com > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > _______________________________________________ > > > > Users mailing list > > > > Users at lists.ironpython.com > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > > > This email is confidential and may be subject to legal or other > > > > professional privilege. It is also subject to copyright. If you have > > > > received it in error, confidentiality and privilege are not waived and you > > > > must not disclose or use the information in it. Please notify the sender by > > > > return email and delete it from your system. Any personal information in > > > > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > > > > > > > > > > > ************************************************************************* > > > > > > > > _______________________________________________ > > > > Users mailing list > > > > Users at lists.ironpython.com > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > _______________________________________________ > > > > Users mailing list > > > > Users at lists.ironpython.com > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > This email is confidential and may be subject to legal or other > > > professional privilege. It is also subject to copyright. If you have > > > received it in error, confidentiality and privilege are not waived and you > > > must not disclose or use the information in it. Please notify the sender by > > > return email and delete it from your system. Any personal information in > > > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > > > > > > > > ************************************************************************* > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > ************************************************************************ > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > This email is confidential and may be subject to legal or other > > professional privilege. It is also subject to copyright. If you have > > received it in error, confidentiality and privilege are not waived and you > > must not disclose or use the information in it. Please notify the sender by > > return email and delete it from your system. Any personal information in > > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > > > > > ************************************************************************* > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fernandoacorreia at gmail.com Fri Feb 22 15:51:53 2008 From: fernandoacorreia at gmail.com (Fernando Correia) Date: Fri, 22 Feb 2008 11:51:53 -0300 Subject: [IronPython] Hosting IronPython 2.0 Alpha 8 Message-ID: <8140eff40802220651i4fbf9d0t8bd918bc43364cf6@mail.gmail.com> I am trying out IronPython hosting on C#. I found out an article about hosting with 2.0 Alpha 6: http://blogs.msdn.com/rdawson/archive/2007/11/29/hosting-ironpython-2-0-alpha-6-via-the-dlr.aspx But those instructions don't seem to work with 2.0 Alpha 8. I've searched the Web but I couldn't find updated instructions. If someone can give me a pointer, I'd appreciate. -------------- next part -------------- An HTML attachment was scrubbed... URL: From curt at hagenlocher.org Fri Feb 22 17:18:22 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Fri, 22 Feb 2008 08:18:22 -0800 Subject: [IronPython] Hosting IronPython 2.0 Alpha 8 In-Reply-To: <8140eff40802220651i4fbf9d0t8bd918bc43364cf6@mail.gmail.com> References: <8140eff40802220651i4fbf9d0t8bd918bc43364cf6@mail.gmail.com> Message-ID: Here's a snippet that I'm using under A8. I can't promise that everything is "right", but it works correctly for how I'm using it. // Load Class1.py into a new scope SourceUnit source = PythonEngine.CurrentEngine.CreateScriptSourceFromFile("Class1.py"); IScriptScope m = PythonEngine.CurrentEngine.CreateScope(); PythonEngine.CurrentEngine.Execute(m, source); // Get the class object for "Class1" object value; m.TryGetVariable("Class1", out value); object theClass = (value as PythonType); // Instantiate "Class1" LanguageContext language = LanguageContext.FromEngine( PythonEngine.CurrentEngine); Scope scope = new Scope(language); CodeContext context = new CodeContext(scope, language); object theValue = new PythonTypeOps.TypeCaller(theClass).Call(context2, new object[0]); // Call the "Clone function on the new instance object theFunction = PythonEngine.CurrentEngine.Operations.GetMember(theValue, "Clone"); object result = PythonEngine.CurrentEngine.Operations.Call(theFunction, new object[] { s, i }); result = PythonEngine.CurrentEngine.Operations.ConvertTo(result); On Fri, Feb 22, 2008 at 6:51 AM, Fernando Correia < fernandoacorreia at gmail.com> wrote: > I am trying out IronPython hosting on C#. I found out an article about > hosting with 2.0 Alpha 6: > > > http://blogs.msdn.com/rdawson/archive/2007/11/29/hosting-ironpython-2-0-alpha-6-via-the-dlr.aspx > > But those instructions don't seem to work with 2.0 Alpha 8. I've searched > the Web but I couldn't find updated instructions. > > If someone can give me a pointer, I'd appreciate. > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From curt at hagenlocher.org Fri Feb 22 17:19:31 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Fri, 22 Feb 2008 08:19:31 -0800 Subject: [IronPython] Hosting IronPython 2.0 Alpha 8 In-Reply-To: References: <8140eff40802220651i4fbf9d0t8bd918bc43364cf6@mail.gmail.com> Message-ID: Sorry... the type of "theClass" should actually be PythonType and not object. On Fri, Feb 22, 2008 at 8:18 AM, Curt Hagenlocher wrote: > Here's a snippet that I'm using under A8. I can't promise that everything > is "right", but it works correctly for how I'm using it. > > // Load Class1.py into a new scope > SourceUnit source = > PythonEngine.CurrentEngine.CreateScriptSourceFromFile("Class1.py"); > IScriptScope m = PythonEngine.CurrentEngine.CreateScope(); > PythonEngine.CurrentEngine.Execute(m, source); > > // Get the class object for "Class1" > object value; > m.TryGetVariable("Class1", out value); > object theClass = (value as PythonType); > // Instantiate "Class1" > LanguageContext language = LanguageContext.FromEngine( > PythonEngine.CurrentEngine); > Scope scope = new Scope(language); > CodeContext context = new CodeContext(scope, language); > object theValue = new PythonTypeOps.TypeCaller(theClass).Call(context2, > new object[0]); > > // Call the "Clone function on the new instance > object theFunction = PythonEngine.CurrentEngine.Operations.GetMember(theValue, > "Clone"); > object result = PythonEngine.CurrentEngine.Operations.Call(theFunction, > new object[] { s, i }); > result = PythonEngine.CurrentEngine.Operations.ConvertTo(result); > > On Fri, Feb 22, 2008 at 6:51 AM, Fernando Correia < > fernandoacorreia at gmail.com> wrote: > > > I am trying out IronPython hosting on C#. I found out an article about > > hosting with 2.0 Alpha 6: > > > > > > http://blogs.msdn.com/rdawson/archive/2007/11/29/hosting-ironpython-2-0-alpha-6-via-the-dlr.aspx > > > > But those instructions don't seem to work with 2.0 Alpha 8. I've > > searched the Web but I couldn't find updated instructions. > > > > If someone can give me a pointer, I'd appreciate. > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dfugate at microsoft.com Fri Feb 22 17:57:41 2008 From: dfugate at microsoft.com (Dave Fugate) Date: Fri, 22 Feb 2008 08:57:41 -0800 Subject: [IronPython] Hosting IronPython 2.0 Alpha 8 In-Reply-To: <8140eff40802220651i4fbf9d0t8bd918bc43364cf6@mail.gmail.com> References: <8140eff40802220651i4fbf9d0t8bd918bc43364cf6@mail.gmail.com> Message-ID: <7346A825E148B049A9AD1D3ED46A2D9123511499A7@NA-EXMSG-C106.redmond.corp.microsoft.com> The tests in the source IronPython distributions should be up to date with respect to the releases. While these aren't as eloquent as the blog entry referenced below, they should give you a good idea of what the IronPython hosting API is like in the release you're using. For example, IronPythonTest\EngineTest.cs and Tests\test_ipye.py are a couple of our hosting tests found in IronPython-2.0A8-Src.zip. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Fernando Correia Sent: Friday, February 22, 2008 6:52 AM To: users at lists.ironpython.com Subject: [IronPython] Hosting IronPython 2.0 Alpha 8 I am trying out IronPython hosting on C#. I found out an article about hosting with 2.0 Alpha 6: http://blogs.msdn.com/rdawson/archive/2007/11/29/hosting-ironpython-2-0-alpha-6-via-the-dlr.aspx But those instructions don't seem to work with 2.0 Alpha 8. I've searched the Web but I couldn't find updated instructions. If someone can give me a pointer, I'd appreciate. -------------- next part -------------- An HTML attachment was scrubbed... URL: From birsch at gmail.com Fri Feb 22 18:40:05 2008 From: birsch at gmail.com (Birsch) Date: Fri, 22 Feb 2008 19:40:05 +0200 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF4EB6D2B@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> <1e4778de0802210830s60e4f13eue81dd421eca4677@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4EB6CCF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802211004k6a3fbdf4i79d8de7fd243c6c1@mail.gmail.com> <47BDC089.90106@houmus.org> <7AD436E4270DD54A94238001769C2227011CF4EB6D2B@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <1e4778de0802220940t433773dek4fcd8f414232f6d6@mail.gmail.com> Dino - do you want me to register a workitem? Also, if I wanted to patch v1.1.1, where should I start? On Thu, Feb 21, 2008 at 8:48 PM, Dino Viehland wrote: > After Birsh's last comment that they're calling compile I was thinking we > might be doing something really stupid. Turns out that we are. For our > supposedly compiled regex's we're not passing the Compiled option. So > they're all getting interpretted and of course that's going to suck big > time. > > So the fix for this is probably to just pass RegexOptions.Compiled to the > Regex object being contructed into RE_Pattern. Internally the Regex class > will compile to dynamic methods (much better than compiling to an assembly > because it'll be collectible). > > It's actually a little more complex than that because we create RE_Pattern > objects for the non-compiled so we need to flow the option in, but it's > still a simple fix. > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto: > users-bounces at lists.ironpython.com] On Behalf Of Dan Shechter > Sent: Thursday, February 21, 2008 10:19 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Slow Performance of CPython libs? > > Just out of curiosity... > I'm guessing that there are two levels of caching that could be used. > One would be to hold a global dictionary of some sort of pattern -> > Regex that will save the lengthy parsing of the re. > > The other would be to actually call Regex.CompileToAssembly to get a > more efficient reperesentation (in runtime that is) of the re. > > Would you (the IP team) favor the former or the latter? > > Shechter. > > > Birsch wrote: > > I checked both sgmllib.py and BeautifulSoup.py - and it seems both are > > reusing the same regexps (searched for re.compile). > > > > I think your suggestion is very relevant in this case. It makes sense to > > replicate the "compile once use many" behavior that is commonly used > > with regexp. > > > > -Birsch > > > > On Thu, Feb 21, 2008 at 7:30 PM, Dino Viehland > > > > wrote: > > > > Do you know if the same reg ex is being used repeatedly? If so > > maybe we can cache & compile the regex instead of interpretting it > > all the time. > > > > > > > > *From:* users-bounces at lists.ironpython.com > > > > [mailto:users-bounces at lists.ironpython.com > > ] *On Behalf Of *Birsch > > *Sent:* Thursday, February 21, 2008 8:30 AM > > > > *To:* Discussion of IronPython > > *Subject:* Re: [IronPython] Slow Performance of CPython libs? > > > > > > > > I took on Cooper's advice and profiled with ANTS. Here are the top > > methods: > > > > *Namespace* > > > > > > > > *Method name* > > > > > > > > *Time (sec.)* > > > > > > > > *Time with children (sec.)* > > > > > > > > *Hit count* > > > > > > > > *Source file* > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Go() > > > > > > > > 37.0189 > > > > > > > > 94.4676 > > > > > > > > 13689612 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Operator() > > > > > > > > 6.2411 > > > > > > > > 6.2411 > > > > > > > > 131146274 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Advance(int i) > > > > > > > > 5.9264 > > > > > > > > 8.7202 > > > > > > > > 66000263 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.SetOperator(int op) > > > > > > > > 5.5750 > > > > > > > > 5.5750 > > > > > > > > 131146274 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Backtrack() > > > > > > > > 5.5692 > > > > > > > > 9.4895 > > > > > > > > 37781343 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.CallWithContext(ICallerContext context, object func, object > > arg0, object arg1) > > > > > > > > 5.5572 > > > > > > > > 114.5245 > > > > > > > > 79754 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Method.Call(ICallerContext context, object arg0) > > > > > > > > 4.9052 > > > > > > > > 114.8251 > > > > > > > > 50886 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > > object arg1) > > > > > > > > 4.8876 > > > > > > > > 114.8059 > > > > > > > > 50886 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Function2.Call(ICallerContext context, object arg0, object arg1) > > > > > > > > 4.6400 > > > > > > > > 114.5471 > > > > > > > > 47486 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.CallWithContext(ICallerContext context, object func, object > arg0) > > > > > > > > 4.2344 > > > > > > > > 114.1604 > > > > > > > > 146658 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexBoyerMoore.Scan(string text, int index, int beglimit, int > endlimit) > > > > > > > > 3.6465 > > > > > > > > 3.6465 > > > > > > > > 13678131 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClassRecursive(char ch, string set, int start) > > > > > > > > 3.6288 > > > > > > > > 5.7113 > > > > > > > > 31508162 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Goto(int newpos) > > > > > > > > 3.2058 > > > > > > > > 5.1470 > > > > > > > > 27364668 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Operand(int i) > > > > > > > > 3.1923 > > > > > > > > 3.1923 > > > > > > > > 73230687 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexRunner.EnsureStorage() > > > > > > > > 3.0803 > > > > > > > > 3.0803 > > > > > > > > 51474823 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClass(char ch, string set) > > > > > > > > 3.0713 > > > > > > > > 8.7827 > > > > > > > > 31508162 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Method.Call(ICallerContext context, object arg0, object arg1) > > > > > > > > 2.9821 > > > > > > > > 7.8675 > > > > > > > > 15012 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > > object arg1, object arg2) > > > > > > > > 2.9794 > > > > > > > > 7.8639 > > > > > > > > 15012 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Forwardcharnext() > > > > > > > > 2.8852 > > > > > > > > 2.8852 > > > > > > > > 62865185 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Forwardchars() > > > > > > > > 2.8279 > > > > > > > > 2.8279 > > > > > > > > 59436277 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClassInternal(char ch, string set, int start, > > int mySetLength, int myCategoryLength) > > > > > > > > 2.0632 > > > > > > > > 2.0826 > > > > > > > > 31508162 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexRunner.Scan(Regex regex, string text, int textbeg, int textend, > > int textstart, int prevlen, bool quick) > > > > > > > > 1.8376 > > > > > > > > 101.7226 > > > > > > > > 43009 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.FindFirstChar() > > > > > > > > 1.6405 > > > > > > > > 5.3456 > > > > > > > > 13701755 > > > > > > > > IronPython.Runtime.Types > > > > > > > > OldClass.TryLookupSlot(SymbolId name, out object ret) > > > > > > > > 1.5573 > > > > > > > > 2.8124 > > > > > > > > 389516 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.GetAttr(ICallerContext context, object o, SymbolId name) > > > > > > > > 1.5365 > > > > > > > > 5.3456 > > > > > > > > 558524 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Textpos() > > > > > > > > 1.4020 > > > > > > > > 1.4020 > > > > > > > > 32648926 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Advance() > > > > > > > > 1.1916 > > > > > > > > 2.9526 > > > > > > > > 13703950 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Textto(int newpos) > > > > > > > > 1.1218 > > > > > > > > 1.1218 > > > > > > > > 24120890 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPeek() > > > > > > > > 1.0579 > > > > > > > > 1.0579 > > > > > > > > 24120894 > > > > > > > > System.Text.RegularExpressions > > > > > > > > Regex.Run(bool quick, int prevlen, string input, int beginning, int > > length, int startat) > > > > > > > > 0.7280 > > > > > > > > 102.4644 > > > > > > > > 43009 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush(int I1) > > > > > > > > 0.6834 > > > > > > > > 0.6834 > > > > > > > > 13745149 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.StackPush(int I1) > > > > > > > > 0.6542 > > > > > > > > 0.6542 > > > > > > > > 13703955 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPop() > > > > > > > > 0.6068 > > > > > > > > 0.6068 > > > > > > > > 13663035 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush() > > > > > > > > 0.6049 > > > > > > > > 0.6049 > > > > > > > > 13708230 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.StackPop() > > > > > > > > 0.5836 > > > > > > > > 0.5836 > > > > > > > > 13703956 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Bump() > > > > > > > > 0.4987 > > > > > > > > 0.4987 > > > > > > > > 10472790 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush(int I1, int I2) > > > > > > > > 0.4864 > > > > > > > > 0.4864 > > > > > > > > 10472790 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPeek(int i) > > > > > > > > 0.4663 > > > > > > > > 0.4663 > > > > > > > > 10457859 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPop(int framesize) > > > > > > > > 0.4396 > > > > > > > > 0.4396 > > > > > > > > 10457859 > > > > > > > > > > Moving up the stack of regex.Go(), most calls originate from > > sgmllib's parse_starttag. > > > > HTH, > > -Birsch > > > > On Thu, Feb 21, 2008 at 2:35 PM, Birsch > > wrote: > > > > Thanks Michael and Dino. > > > > I'll prof and send update. Got a good profiler recommendation for > .Net? > > Meanwhile I noticed the sample site below causes BeautifulSoup to > > generate quite a few [python] exceptions during __init__. Does > > IronPython handle exceptions significantly slower than CPtyhon? > > > > Repro code is simple (just build a BeautifulSoup obj with mininova's > > home page). > > Here are the .py and .cs I used to time the diffs: > > > > *bstest.py:* > > #Bypass CPython default socket implementation with IPCE/FePy > > import imp, os, sys > > sys.modules['socket'] = module = imp.new_module('socket') > > execfile('socket.py', module.__dict__) > > > > from BeautifulSoup import BeautifulSoup > > from urllib import urlopen > > import datetime > > > > def getContent(url): > > #Download html data > > startTime = datetime.datetime.now() > > print "Getting url", url > > html = urlopen(url).read() > > print "Time taken:", datetime.datetime.now() - startTime > > > > #Make soup > > startTime = datetime.datetime.now() > > print "Making soup..." > > soup = BeautifulSoup(markup=html) > > print "Time taken:", datetime.datetime.now() - startTime > > > > if __name__ == "__main__": > > print getContent("www.mininova.org ") > > > > > > *C#:* > > using System; > > using System.Collections.Generic; > > using System.Text; > > using IronPython.Hosting; > > > > namespace IronPythonBeautifulSoupTest > > { > > public class Program > > { > > public static void Main(string[] args) > > { > > //Init > > System.Console.WriteLine("Starting..."); > > DateTime start = DateTime.Now; > > PythonEngine engine = new PythonEngine(); > > > > //Add paths: > > //BeautifulSoup.py, socket.py, bstest.py located on exe > dir > > engine.AddToPath(@"."); > > //CPython Lib (replace with your own) > > engine.AddToPath(@"D:\Dev\Python\Lib"); > > > > //Import and load > > TimeSpan span = DateTime.Now - start; > > System.Console.WriteLine("[1] Import: " + > > span.TotalSeconds); > > DateTime d = DateTime.Now; > > engine.ExecuteFile(@"bstest.py"); > > span = DateTime.Now - d; > > System.Console.WriteLine("[2] Load: " + > span.TotalSeconds); > > > > //Execute > > d = DateTime.Now; > > engine.Execute("getContent(\"http://www.mininova.org\ > ")"); > > span = DateTime.Now - d; > > System.Console.WriteLine("[3] Execute: " + > > span.TotalSeconds); > > span = DateTime.Now - start; > > System.Console.WriteLine("Total: " + span.TotalSeconds); > > > > > > } > > } > > } > > > > > > On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland > > > > > wrote: > > > > We've actually had this issue reported once before a long time ago - > > it's a very low CodePlex ID - > > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 > > > > We haven't had a chance to investigate the end-to-end scenario. If > > someone could come up with a smaller simpler repro that'd be great. > > Otherwise we haven't forgotten about it we've just had more > > immediately pressing issues to work on :(. > > > > > > -----Original Message----- > > From: users-bounces at lists.ironpython.com > > > > [mailto:users-bounces at lists.ironpython.com > > ] On Behalf Of Michael > Foord > > Sent: Wednesday, February 20, 2008 5:20 AM > > To: Discussion of IronPython > > Subject: Re: [IronPython] Slow Performance of CPython libs? > > > > Birsch wrote: > > > Hi - We've been using IronPython successfully to allow > extensibility > > > of our application. > > > > > > Overall we are happy with the performance, with the exception of > > > BeautifulSoup which seems to run very slowly: x5 or more time to > > > execute compared to CPython. > > > > > > Most of the time seems to be spent during __init__() of BS, where > the > > > markup is parsed. > > > > > > We suspect this has to do with the fact that our CPython env is > > > executing .pyc files and can precompile its libs, while the > > IronPython > > > environment compiles each iteration. We couldn't find a way to > > > pre-compile the libs and then introduce them into the code, but > > in any > > > case this will result in a large management overhead since the > amount > > > of CPython libs we expose to our users contains 100's of modules. > > > > > > Any ideas on how to optimize? > > > > I think it is worth doing real profiling to find out where the time > is > > being spent during parsing. > > > > If it is spending most of the time in '__init__' then the time is > > probably not spent in importing - so compilation isn't relevant and > it > > is a runtime performance issue. (Importing is much slower with > > IronPython and at Resolver Systems we do use precompiled binaries - > but > > strangely enough it doesn't provide much of a performance gain.) > > > > Michael > > http://www.manning.com/foord > > > > > > > > Thanks, > > > -Birsch > > > > > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 runtime > DLLs > > > (this was done to overcome library incompatibilities and network > > > errors). However, the relevant slow .py code (mainly SGMLParser > and > > > BeautifulSoup) is the same. > > > > > > ------------------------------------------------------------------------ > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at voidspace.org.uk Fri Feb 22 19:27:19 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Fri, 22 Feb 2008 18:27:19 +0000 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <1e4778de0802220940t433773dek4fcd8f414232f6d6@mail.gmail.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> <1e4778de0802210830s60e4f13eue81dd421eca4677@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4EB6CCF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802211004k6a3fbdf4i79d8de7fd243c6c1@mail.gmail.com> <47BDC089.90106@houmus.org> <7AD436E4270DD54A94238001769C2227011CF4EB6D2B@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802220940t433773dek4fcd8f414232f6d6@mail.gmail.com> Message-ID: <47BF1407.4020404@voidspace.org.uk> Birsch wrote: > Dino - do you want me to register a workitem? Also, if I wanted to > patch v1.1.1, where should I start? This is a good point. As you fix bugs is it possible to at least mark which ones might be suitable to fold back into 1.1. This and the socket bugs recently discussed would be really great to see fixed in a 1.1.2 release... Thanks Michael Foord http://www.manning.com/foord > > On Thu, Feb 21, 2008 at 8:48 PM, Dino Viehland > > > wrote: > > After Birsh's last comment that they're calling compile I was > thinking we might be doing something really stupid. Turns out > that we are. For our supposedly compiled regex's we're not > passing the Compiled option. So they're all getting interpretted > and of course that's going to suck big time. > > So the fix for this is probably to just pass RegexOptions.Compiled > to the Regex object being contructed into RE_Pattern. Internally > the Regex class will compile to dynamic methods (much better than > compiling to an assembly because it'll be collectible). > > It's actually a little more complex than that because we create > RE_Pattern objects for the non-compiled so we need to flow the > option in, but it's still a simple fix. > > -----Original Message----- > From: users-bounces at lists.ironpython.com > > [mailto:users-bounces at lists.ironpython.com > ] On Behalf Of Dan Shechter > Sent: Thursday, February 21, 2008 10:19 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Slow Performance of CPython libs? > > Just out of curiosity... > I'm guessing that there are two levels of caching that could be used. > One would be to hold a global dictionary of some sort of pattern -> > Regex that will save the lengthy parsing of the re. > > The other would be to actually call Regex.CompileToAssembly to get a > more efficient reperesentation (in runtime that is) of the re. > > Would you (the IP team) favor the former or the latter? > > Shechter. > > > Birsch wrote: > > I checked both sgmllib.py and BeautifulSoup.py - and it seems > both are > > reusing the same regexps (searched for re.compile). > > > > I think your suggestion is very relevant in this case. It makes > sense to > > replicate the "compile once use many" behavior that is commonly used > > with regexp. > > > > -Birsch > > > > On Thu, Feb 21, 2008 at 7:30 PM, Dino Viehland > > > >> wrote: > > > > Do you know if the same reg ex is being used repeatedly? If so > > maybe we can cache & compile the regex instead of > interpretting it > > all the time. > > > > > > > > *From:* users-bounces at lists.ironpython.com > > > > > > [mailto:users-bounces at lists.ironpython.com > > > >] *On Behalf Of *Birsch > > *Sent:* Thursday, February 21, 2008 8:30 AM > > > > *To:* Discussion of IronPython > > *Subject:* Re: [IronPython] Slow Performance of CPython libs? > > > > > > > > I took on Cooper's advice and profiled with ANTS. Here are > the top > > methods: > > > > *Namespace* > > > > > > > > *Method name* > > > > > > > > *Time (sec.)* > > > > > > > > *Time with children (sec.)* > > > > > > > > *Hit count* > > > > > > > > *Source file* > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Go() > > > > > > > > 37.0189 > > > > > > > > 94.4676 > > > > > > > > 13689612 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Operator() > > > > > > > > 6.2411 > > > > > > > > 6.2411 > > > > > > > > 131146274 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Advance(int i) > > > > > > > > 5.9264 > > > > > > > > 8.7202 > > > > > > > > 66000263 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.SetOperator(int op) > > > > > > > > 5.5750 > > > > > > > > 5.5750 > > > > > > > > 131146274 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Backtrack() > > > > > > > > 5.5692 > > > > > > > > 9.4895 > > > > > > > > 37781343 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.CallWithContext(ICallerContext context, object func, object > > arg0, object arg1) > > > > > > > > 5.5572 > > > > > > > > 114.5245 > > > > > > > > 79754 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Method.Call(ICallerContext context, object arg0) > > > > > > > > 4.9052 > > > > > > > > 114.8251 > > > > > > > > 50886 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > > object arg1) > > > > > > > > 4.8876 > > > > > > > > 114.8059 > > > > > > > > 50886 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Function2.Call(ICallerContext context, object arg0, object arg1) > > > > > > > > 4.6400 > > > > > > > > 114.5471 > > > > > > > > 47486 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.CallWithContext(ICallerContext context, object func, > object arg0) > > > > > > > > 4.2344 > > > > > > > > 114.1604 > > > > > > > > 146658 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexBoyerMoore.Scan(string text, int index, int beglimit, > int endlimit) > > > > > > > > 3.6465 > > > > > > > > 3.6465 > > > > > > > > 13678131 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClassRecursive(char ch, string set, int > start) > > > > > > > > 3.6288 > > > > > > > > 5.7113 > > > > > > > > 31508162 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Goto(int newpos) > > > > > > > > 3.2058 > > > > > > > > 5.1470 > > > > > > > > 27364668 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Operand(int i) > > > > > > > > 3.1923 > > > > > > > > 3.1923 > > > > > > > > 73230687 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexRunner.EnsureStorage() > > > > > > > > 3.0803 > > > > > > > > 3.0803 > > > > > > > > 51474823 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClass(char ch, string set) > > > > > > > > 3.0713 > > > > > > > > 8.7827 > > > > > > > > 31508162 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Method.Call(ICallerContext context, object arg0, object arg1) > > > > > > > > 2.9821 > > > > > > > > 7.8675 > > > > > > > > 15012 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > > object arg1, object arg2) > > > > > > > > 2.9794 > > > > > > > > 7.8639 > > > > > > > > 15012 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Forwardcharnext() > > > > > > > > 2.8852 > > > > > > > > 2.8852 > > > > > > > > 62865185 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Forwardchars() > > > > > > > > 2.8279 > > > > > > > > 2.8279 > > > > > > > > 59436277 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClassInternal(char ch, string set, int > start, > > int mySetLength, int myCategoryLength) > > > > > > > > 2.0632 > > > > > > > > 2.0826 > > > > > > > > 31508162 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexRunner.Scan(Regex regex, string text, int textbeg, int > textend, > > int textstart, int prevlen, bool quick) > > > > > > > > 1.8376 > > > > > > > > 101.7226 > > > > > > > > 43009 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.FindFirstChar() > > > > > > > > 1.6405 > > > > > > > > 5.3456 > > > > > > > > 13701755 > > > > > > > > IronPython.Runtime.Types > > > > > > > > OldClass.TryLookupSlot(SymbolId name, out object ret) > > > > > > > > 1.5573 > > > > > > > > 2.8124 > > > > > > > > 389516 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.GetAttr(ICallerContext context, object o, SymbolId name) > > > > > > > > 1.5365 > > > > > > > > 5.3456 > > > > > > > > 558524 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Textpos() > > > > > > > > 1.4020 > > > > > > > > 1.4020 > > > > > > > > 32648926 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Advance() > > > > > > > > 1.1916 > > > > > > > > 2.9526 > > > > > > > > 13703950 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Textto(int newpos) > > > > > > > > 1.1218 > > > > > > > > 1.1218 > > > > > > > > 24120890 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPeek() > > > > > > > > 1.0579 > > > > > > > > 1.0579 > > > > > > > > 24120894 > > > > > > > > System.Text.RegularExpressions > > > > > > > > Regex.Run(bool quick, int prevlen, string input, int > beginning, int > > length, int startat) > > > > > > > > 0.7280 > > > > > > > > 102.4644 > > > > > > > > 43009 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush(int I1) > > > > > > > > 0.6834 > > > > > > > > 0.6834 > > > > > > > > 13745149 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.StackPush(int I1) > > > > > > > > 0.6542 > > > > > > > > 0.6542 > > > > > > > > 13703955 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPop() > > > > > > > > 0.6068 > > > > > > > > 0.6068 > > > > > > > > 13663035 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush() > > > > > > > > 0.6049 > > > > > > > > 0.6049 > > > > > > > > 13708230 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.StackPop() > > > > > > > > 0.5836 > > > > > > > > 0.5836 > > > > > > > > 13703956 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Bump() > > > > > > > > 0.4987 > > > > > > > > 0.4987 > > > > > > > > 10472790 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush(int I1, int I2) > > > > > > > > 0.4864 > > > > > > > > 0.4864 > > > > > > > > 10472790 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPeek(int i) > > > > > > > > 0.4663 > > > > > > > > 0.4663 > > > > > > > > 10457859 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPop(int framesize) > > > > > > > > 0.4396 > > > > > > > > 0.4396 > > > > > > > > 10457859 > > > > > > > > > > Moving up the stack of regex.Go(), most calls originate from > > sgmllib's parse_starttag. > > > > HTH, > > -Birsch > > > > On Thu, Feb 21, 2008 at 2:35 PM, Birsch > > >> wrote: > > > > Thanks Michael and Dino. > > > > I'll prof and send update. Got a good profiler > recommendation for .Net? > > Meanwhile I noticed the sample site below causes > BeautifulSoup to > > generate quite a few [python] exceptions during __init__. Does > > IronPython handle exceptions significantly slower than CPtyhon? > > > > Repro code is simple (just build a BeautifulSoup obj with > mininova's > > home page). > > Here are the .py and .cs I used to time the diffs: > > > > *bstest.py:* > > #Bypass CPython default socket implementation with IPCE/FePy > > import imp, os, sys > > sys.modules['socket'] = module = imp.new_module('socket') > > execfile('socket.py', module.__dict__) > > > > from BeautifulSoup import BeautifulSoup > > from urllib import urlopen > > import datetime > > > > def getContent(url): > > #Download html data > > startTime = datetime.datetime.now() > > print "Getting url", url > > html = urlopen(url).read() > > print "Time taken:", datetime.datetime.now() - startTime > > > > #Make soup > > startTime = datetime.datetime.now() > > print "Making soup..." > > soup = BeautifulSoup(markup=html) > > print "Time taken:", datetime.datetime.now() - startTime > > > > if __name__ == "__main__": > > print getContent("www.mininova.org > ") > > > > > > *C#:* > > using System; > > using System.Collections.Generic; > > using System.Text; > > using IronPython.Hosting; > > > > namespace IronPythonBeautifulSoupTest > > { > > public class Program > > { > > public static void Main(string[] args) > > { > > //Init > > System.Console.WriteLine("Starting..."); > > DateTime start = DateTime.Now; > > PythonEngine engine = new PythonEngine(); > > > > //Add paths: > > //BeautifulSoup.py, socket.py, bstest.py located > on exe dir > > engine.AddToPath(@"."); > > //CPython Lib (replace with your own) > > engine.AddToPath(@"D:\Dev\Python\Lib"); > > > > //Import and load > > TimeSpan span = DateTime.Now - start; > > System.Console.WriteLine("[1] Import: " + > > span.TotalSeconds); > > DateTime d = DateTime.Now; > > engine.ExecuteFile(@"bstest.py"); > > span = DateTime.Now - d; > > System.Console.WriteLine("[2] Load: " + > span.TotalSeconds); > > > > //Execute > > d = DateTime.Now; > > > engine.Execute("getContent(\"http://www.mininova.org\ > ")"); > > span = DateTime.Now - d; > > System.Console.WriteLine("[3] Execute: " + > > span.TotalSeconds); > > span = DateTime.Now - start; > > System.Console.WriteLine("Total: " + > span.TotalSeconds); > > > > > > } > > } > > } > > > > > > On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland > > > >> > > wrote: > > > > We've actually had this issue reported once before a long > time ago - > > it's a very low CodePlex ID - > > > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 > > > > We haven't had a chance to investigate the end-to-end > scenario. If > > someone could come up with a smaller simpler repro that'd be > great. > > Otherwise we haven't forgotten about it we've just had more > > immediately pressing issues to work on :(. > > > > > > -----Original Message----- > > From: users-bounces at lists.ironpython.com > > > > > > [mailto:users-bounces at lists.ironpython.com > > > >] On Behalf Of Michael > Foord > > Sent: Wednesday, February 20, 2008 5:20 AM > > To: Discussion of IronPython > > Subject: Re: [IronPython] Slow Performance of CPython libs? > > > > Birsch wrote: > > > Hi - We've been using IronPython successfully to allow > extensibility > > > of our application. > > > > > > Overall we are happy with the performance, with the > exception of > > > BeautifulSoup which seems to run very slowly: x5 or more > time to > > > execute compared to CPython. > > > > > > Most of the time seems to be spent during __init__() of > BS, where the > > > markup is parsed. > > > > > > We suspect this has to do with the fact that our CPython > env is > > > executing .pyc files and can precompile its libs, while the > > IronPython > > > environment compiles each iteration. We couldn't find a > way to > > > pre-compile the libs and then introduce them into the > code, but > > in any > > > case this will result in a large management overhead > since the amount > > > of CPython libs we expose to our users contains 100's of > modules. > > > > > > Any ideas on how to optimize? > > > > I think it is worth doing real profiling to find out where > the time is > > being spent during parsing. > > > > If it is spending most of the time in '__init__' then the > time is > > probably not spent in importing - so compilation isn't > relevant and it > > is a runtime performance issue. (Importing is much slower with > > IronPython and at Resolver Systems we do use precompiled > binaries - but > > strangely enough it doesn't provide much of a performance gain.) > > > > Michael > > http://www.manning.com/foord > > > > > > > > Thanks, > > > -Birsch > > > > > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 > runtime DLLs > > > (this was done to overcome library incompatibilities and > network > > > errors). However, the relevant slow .py code (mainly > SGMLParser and > > > BeautifulSoup) is the same. > > > > > > ------------------------------------------------------------------------ > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From fuzzyman at voidspace.org.uk Fri Feb 22 19:29:51 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Fri, 22 Feb 2008 18:29:51 +0000 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <1e4778de0802220940t433773dek4fcd8f414232f6d6@mail.gmail.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> <1e4778de0802210830s60e4f13eue81dd421eca4677@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4EB6CCF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802211004k6a3fbdf4i79d8de7fd243c6c1@mail.gmail.com> <47BDC089.90106@houmus.org> <7AD436E4270DD54A94238001769C2227011CF4EB6D2B@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802220940t433773dek4fcd8f414232f6d6@mail.gmail.com> Message-ID: <47BF149F.7040300@voidspace.org.uk> Birsch wrote: > Dino - do you want me to register a workitem? Also, if I wanted to > patch v1.1.1, where should I start? This is a good point. As you fix bugs is it possible to at least mark which ones might be suitable to fold back into 1.1. This and the socket bugs recently discussed would be really great to see fixed in a 1.1.2 release... Thanks Michael Foord http://www.manning.com/foord > > On Thu, Feb 21, 2008 at 8:48 PM, Dino Viehland > > > wrote: > > After Birsh's last comment that they're calling compile I was > thinking we might be doing something really stupid. Turns out > that we are. For our supposedly compiled regex's we're not > passing the Compiled option. So they're all getting interpretted > and of course that's going to suck big time. > > So the fix for this is probably to just pass RegexOptions.Compiled > to the Regex object being contructed into RE_Pattern. Internally > the Regex class will compile to dynamic methods (much better than > compiling to an assembly because it'll be collectible). > > It's actually a little more complex than that because we create > RE_Pattern objects for the non-compiled so we need to flow the > option in, but it's still a simple fix. > > -----Original Message----- > From: users-bounces at lists.ironpython.com > > [mailto:users-bounces at lists.ironpython.com > ] On Behalf Of Dan Shechter > Sent: Thursday, February 21, 2008 10:19 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Slow Performance of CPython libs? > > Just out of curiosity... > I'm guessing that there are two levels of caching that could be used. > One would be to hold a global dictionary of some sort of pattern -> > Regex that will save the lengthy parsing of the re. > > The other would be to actually call Regex.CompileToAssembly to get a > more efficient reperesentation (in runtime that is) of the re. > > Would you (the IP team) favor the former or the latter? > > Shechter. > > > Birsch wrote: > > I checked both sgmllib.py and BeautifulSoup.py - and it seems > both are > > reusing the same regexps (searched for re.compile). > > > > I think your suggestion is very relevant in this case. It makes > sense to > > replicate the "compile once use many" behavior that is commonly used > > with regexp. > > > > -Birsch > > > > On Thu, Feb 21, 2008 at 7:30 PM, Dino Viehland > > > >> wrote: > > > > Do you know if the same reg ex is being used repeatedly? If so > > maybe we can cache & compile the regex instead of > interpretting it > > all the time. > > > > > > > > *From:* users-bounces at lists.ironpython.com > > > > > > [mailto:users-bounces at lists.ironpython.com > > > >] *On Behalf Of *Birsch > > *Sent:* Thursday, February 21, 2008 8:30 AM > > > > *To:* Discussion of IronPython > > *Subject:* Re: [IronPython] Slow Performance of CPython libs? > > > > > > > > I took on Cooper's advice and profiled with ANTS. Here are > the top > > methods: > > > > *Namespace* > > > > > > > > *Method name* > > > > > > > > *Time (sec.)* > > > > > > > > *Time with children (sec.)* > > > > > > > > *Hit count* > > > > > > > > *Source file* > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Go() > > > > > > > > 37.0189 > > > > > > > > 94.4676 > > > > > > > > 13689612 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Operator() > > > > > > > > 6.2411 > > > > > > > > 6.2411 > > > > > > > > 131146274 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Advance(int i) > > > > > > > > 5.9264 > > > > > > > > 8.7202 > > > > > > > > 66000263 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.SetOperator(int op) > > > > > > > > 5.5750 > > > > > > > > 5.5750 > > > > > > > > 131146274 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Backtrack() > > > > > > > > 5.5692 > > > > > > > > 9.4895 > > > > > > > > 37781343 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.CallWithContext(ICallerContext context, object func, object > > arg0, object arg1) > > > > > > > > 5.5572 > > > > > > > > 114.5245 > > > > > > > > 79754 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Method.Call(ICallerContext context, object arg0) > > > > > > > > 4.9052 > > > > > > > > 114.8251 > > > > > > > > 50886 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > > object arg1) > > > > > > > > 4.8876 > > > > > > > > 114.8059 > > > > > > > > 50886 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Function2.Call(ICallerContext context, object arg0, object arg1) > > > > > > > > 4.6400 > > > > > > > > 114.5471 > > > > > > > > 47486 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.CallWithContext(ICallerContext context, object func, > object arg0) > > > > > > > > 4.2344 > > > > > > > > 114.1604 > > > > > > > > 146658 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexBoyerMoore.Scan(string text, int index, int beglimit, > int endlimit) > > > > > > > > 3.6465 > > > > > > > > 3.6465 > > > > > > > > 13678131 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClassRecursive(char ch, string set, int > start) > > > > > > > > 3.6288 > > > > > > > > 5.7113 > > > > > > > > 31508162 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Goto(int newpos) > > > > > > > > 3.2058 > > > > > > > > 5.1470 > > > > > > > > 27364668 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Operand(int i) > > > > > > > > 3.1923 > > > > > > > > 3.1923 > > > > > > > > 73230687 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexRunner.EnsureStorage() > > > > > > > > 3.0803 > > > > > > > > 3.0803 > > > > > > > > 51474823 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClass(char ch, string set) > > > > > > > > 3.0713 > > > > > > > > 8.7827 > > > > > > > > 31508162 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Method.Call(ICallerContext context, object arg0, object arg1) > > > > > > > > 2.9821 > > > > > > > > 7.8675 > > > > > > > > 15012 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > > object arg1, object arg2) > > > > > > > > 2.9794 > > > > > > > > 7.8639 > > > > > > > > 15012 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Forwardcharnext() > > > > > > > > 2.8852 > > > > > > > > 2.8852 > > > > > > > > 62865185 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Forwardchars() > > > > > > > > 2.8279 > > > > > > > > 2.8279 > > > > > > > > 59436277 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClassInternal(char ch, string set, int > start, > > int mySetLength, int myCategoryLength) > > > > > > > > 2.0632 > > > > > > > > 2.0826 > > > > > > > > 31508162 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexRunner.Scan(Regex regex, string text, int textbeg, int > textend, > > int textstart, int prevlen, bool quick) > > > > > > > > 1.8376 > > > > > > > > 101.7226 > > > > > > > > 43009 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.FindFirstChar() > > > > > > > > 1.6405 > > > > > > > > 5.3456 > > > > > > > > 13701755 > > > > > > > > IronPython.Runtime.Types > > > > > > > > OldClass.TryLookupSlot(SymbolId name, out object ret) > > > > > > > > 1.5573 > > > > > > > > 2.8124 > > > > > > > > 389516 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.GetAttr(ICallerContext context, object o, SymbolId name) > > > > > > > > 1.5365 > > > > > > > > 5.3456 > > > > > > > > 558524 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Textpos() > > > > > > > > 1.4020 > > > > > > > > 1.4020 > > > > > > > > 32648926 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Advance() > > > > > > > > 1.1916 > > > > > > > > 2.9526 > > > > > > > > 13703950 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Textto(int newpos) > > > > > > > > 1.1218 > > > > > > > > 1.1218 > > > > > > > > 24120890 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPeek() > > > > > > > > 1.0579 > > > > > > > > 1.0579 > > > > > > > > 24120894 > > > > > > > > System.Text.RegularExpressions > > > > > > > > Regex.Run(bool quick, int prevlen, string input, int > beginning, int > > length, int startat) > > > > > > > > 0.7280 > > > > > > > > 102.4644 > > > > > > > > 43009 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush(int I1) > > > > > > > > 0.6834 > > > > > > > > 0.6834 > > > > > > > > 13745149 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.StackPush(int I1) > > > > > > > > 0.6542 > > > > > > > > 0.6542 > > > > > > > > 13703955 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPop() > > > > > > > > 0.6068 > > > > > > > > 0.6068 > > > > > > > > 13663035 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush() > > > > > > > > 0.6049 > > > > > > > > 0.6049 > > > > > > > > 13708230 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.StackPop() > > > > > > > > 0.5836 > > > > > > > > 0.5836 > > > > > > > > 13703956 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Bump() > > > > > > > > 0.4987 > > > > > > > > 0.4987 > > > > > > > > 10472790 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush(int I1, int I2) > > > > > > > > 0.4864 > > > > > > > > 0.4864 > > > > > > > > 10472790 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPeek(int i) > > > > > > > > 0.4663 > > > > > > > > 0.4663 > > > > > > > > 10457859 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPop(int framesize) > > > > > > > > 0.4396 > > > > > > > > 0.4396 > > > > > > > > 10457859 > > > > > > > > > > Moving up the stack of regex.Go(), most calls originate from > > sgmllib's parse_starttag. > > > > HTH, > > -Birsch > > > > On Thu, Feb 21, 2008 at 2:35 PM, Birsch > > >> wrote: > > > > Thanks Michael and Dino. > > > > I'll prof and send update. Got a good profiler > recommendation for .Net? > > Meanwhile I noticed the sample site below causes > BeautifulSoup to > > generate quite a few [python] exceptions during __init__. Does > > IronPython handle exceptions significantly slower than CPtyhon? > > > > Repro code is simple (just build a BeautifulSoup obj with > mininova's > > home page). > > Here are the .py and .cs I used to time the diffs: > > > > *bstest.py:* > > #Bypass CPython default socket implementation with IPCE/FePy > > import imp, os, sys > > sys.modules['socket'] = module = imp.new_module('socket') > > execfile('socket.py', module.__dict__) > > > > from BeautifulSoup import BeautifulSoup > > from urllib import urlopen > > import datetime > > > > def getContent(url): > > #Download html data > > startTime = datetime.datetime.now() > > print "Getting url", url > > html = urlopen(url).read() > > print "Time taken:", datetime.datetime.now() - startTime > > > > #Make soup > > startTime = datetime.datetime.now() > > print "Making soup..." > > soup = BeautifulSoup(markup=html) > > print "Time taken:", datetime.datetime.now() - startTime > > > > if __name__ == "__main__": > > print getContent("www.mininova.org > ") > > > > > > *C#:* > > using System; > > using System.Collections.Generic; > > using System.Text; > > using IronPython.Hosting; > > > > namespace IronPythonBeautifulSoupTest > > { > > public class Program > > { > > public static void Main(string[] args) > > { > > //Init > > System.Console.WriteLine("Starting..."); > > DateTime start = DateTime.Now; > > PythonEngine engine = new PythonEngine(); > > > > //Add paths: > > //BeautifulSoup.py, socket.py, bstest.py located > on exe dir > > engine.AddToPath(@"."); > > //CPython Lib (replace with your own) > > engine.AddToPath(@"D:\Dev\Python\Lib"); > > > > //Import and load > > TimeSpan span = DateTime.Now - start; > > System.Console.WriteLine("[1] Import: " + > > span.TotalSeconds); > > DateTime d = DateTime.Now; > > engine.ExecuteFile(@"bstest.py"); > > span = DateTime.Now - d; > > System.Console.WriteLine("[2] Load: " + > span.TotalSeconds); > > > > //Execute > > d = DateTime.Now; > > > engine.Execute("getContent(\"http://www.mininova.org\ > ")"); > > span = DateTime.Now - d; > > System.Console.WriteLine("[3] Execute: " + > > span.TotalSeconds); > > span = DateTime.Now - start; > > System.Console.WriteLine("Total: " + > span.TotalSeconds); > > > > > > } > > } > > } > > > > > > On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland > > > >> > > wrote: > > > > We've actually had this issue reported once before a long > time ago - > > it's a very low CodePlex ID - > > > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 > > > > We haven't had a chance to investigate the end-to-end > scenario. If > > someone could come up with a smaller simpler repro that'd be > great. > > Otherwise we haven't forgotten about it we've just had more > > immediately pressing issues to work on :(. > > > > > > -----Original Message----- > > From: users-bounces at lists.ironpython.com > > > > > > [mailto:users-bounces at lists.ironpython.com > > > >] On Behalf Of Michael > Foord > > Sent: Wednesday, February 20, 2008 5:20 AM > > To: Discussion of IronPython > > Subject: Re: [IronPython] Slow Performance of CPython libs? > > > > Birsch wrote: > > > Hi - We've been using IronPython successfully to allow > extensibility > > > of our application. > > > > > > Overall we are happy with the performance, with the > exception of > > > BeautifulSoup which seems to run very slowly: x5 or more > time to > > > execute compared to CPython. > > > > > > Most of the time seems to be spent during __init__() of > BS, where the > > > markup is parsed. > > > > > > We suspect this has to do with the fact that our CPython > env is > > > executing .pyc files and can precompile its libs, while the > > IronPython > > > environment compiles each iteration. We couldn't find a > way to > > > pre-compile the libs and then introduce them into the > code, but > > in any > > > case this will result in a large management overhead > since the amount > > > of CPython libs we expose to our users contains 100's of > modules. > > > > > > Any ideas on how to optimize? > > > > I think it is worth doing real profiling to find out where > the time is > > being spent during parsing. > > > > If it is spending most of the time in '__init__' then the > time is > > probably not spent in importing - so compilation isn't > relevant and it > > is a runtime performance issue. (Importing is much slower with > > IronPython and at Resolver Systems we do use precompiled > binaries - but > > strangely enough it doesn't provide much of a performance gain.) > > > > Michael > > http://www.manning.com/foord > > > > > > > > Thanks, > > > -Birsch > > > > > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 > runtime DLLs > > > (this was done to overcome library incompatibilities and > network > > > errors). However, the relevant slow .py code (mainly > SGMLParser and > > > BeautifulSoup) is the same. > > > > > > ------------------------------------------------------------------------ > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From dinov at exchange.microsoft.com Fri Feb 22 19:55:42 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Fri, 22 Feb 2008 10:55:42 -0800 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <1e4778de0802220940t433773dek4fcd8f414232f6d6@mail.gmail.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> <1e4778de0802210830s60e4f13eue81dd421eca4677@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4EB6CCF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802211004k6a3fbdf4i79d8de7fd243c6c1@mail.gmail.com> <47BDC089.90106@houmus.org> <7AD436E4270DD54A94238001769C2227011CF4EB6D2B@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802220940t433773dek4fcd8f414232f6d6@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4EB7025@DF-GRTDANE-MSG.exchange.corp.microsoft.com> For patching 1.1.1 you just need to flow a bool from the compile methods in RE into RE_Pattern and then if the flag is set pass in RegexOptions.Compiled if the flag is true. My change ended up looking like: public static RE_Pattern compile(object pattern) { try { - return new RE_Pattern(ValidatePattern(pattern)); + return new RE_Pattern(ValidatePattern(pattern), 0, true); } catch (ArgumentException e) { throw PythonExceptions.CreateThrowable(error, e.Message); } } public static RE_Pattern compile(object pattern, object flags) { try { - return new RE_Pattern(ValidatePattern(pattern), Converter.ConvertToInt32(flags)); + return new RE_Pattern(ValidatePattern(pattern), Converter.ConvertToInt32(flags), true); } catch (ArgumentException e) { throw PythonExceptions.CreateThrowable(error, e.Message); } } - public RE_Pattern(object pattern) + internal RE_Pattern(object pattern) : this(pattern, 0) { } - public RE_Pattern(object pattern, int flags) { + internal RE_Pattern(object pattern, int flags) : + this(pattern, flags, false) { + } + internal RE_Pattern(object pattern, int flags, bool compiled) { _pre = PreParseRegex(ValidatePattern(pattern)); try { RegexOptions opts = FlagsToOption(flags); +#if SILVERLIGHT this._re = new Regex(_pre.Pattern, opts); +#else + this._re = new Regex(_pre.Pattern, opts | (compiled ? RegexOptions.Compiled : RegexOptions.None)); +#endif From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Birsch Sent: Friday, February 22, 2008 9:40 AM To: Discussion of IronPython Subject: Re: [IronPython] Slow Performance of CPython libs? Dino - do you want me to register a workitem? Also, if I wanted to patch v1.1.1, where should I start? On Thu, Feb 21, 2008 at 8:48 PM, Dino Viehland > wrote: After Birsh's last comment that they're calling compile I was thinking we might be doing something really stupid. Turns out that we are. For our supposedly compiled regex's we're not passing the Compiled option. So they're all getting interpretted and of course that's going to suck big time. So the fix for this is probably to just pass RegexOptions.Compiled to the Regex object being contructed into RE_Pattern. Internally the Regex class will compile to dynamic methods (much better than compiling to an assembly because it'll be collectible). It's actually a little more complex than that because we create RE_Pattern objects for the non-compiled so we need to flow the option in, but it's still a simple fix. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dan Shechter Sent: Thursday, February 21, 2008 10:19 AM To: Discussion of IronPython Subject: Re: [IronPython] Slow Performance of CPython libs? Just out of curiosity... I'm guessing that there are two levels of caching that could be used. One would be to hold a global dictionary of some sort of pattern -> Regex that will save the lengthy parsing of the re. The other would be to actually call Regex.CompileToAssembly to get a more efficient reperesentation (in runtime that is) of the re. Would you (the IP team) favor the former or the latter? Shechter. Birsch wrote: > I checked both sgmllib.py and BeautifulSoup.py - and it seems both are > reusing the same regexps (searched for re.compile). > > I think your suggestion is very relevant in this case. It makes sense to > replicate the "compile once use many" behavior that is commonly used > with regexp. > > -Birsch > > On Thu, Feb 21, 2008 at 7:30 PM, Dino Viehland > >> wrote: > > Do you know if the same reg ex is being used repeatedly? If so > maybe we can cache & compile the regex instead of interpretting it > all the time. > > > > *From:* users-bounces at lists.ironpython.com > > > [mailto:users-bounces at lists.ironpython.com > >] *On Behalf Of *Birsch > *Sent:* Thursday, February 21, 2008 8:30 AM > > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] Slow Performance of CPython libs? > > > > I took on Cooper's advice and profiled with ANTS. Here are the top > methods: > > *Namespace* > > > > *Method name* > > > > *Time (sec.)* > > > > *Time with children (sec.)* > > > > *Hit count* > > > > *Source file* > > System.Text.RegularExpressions > > > > RegexInterpreter.Go() > > > > 37.0189 > > > > 94.4676 > > > > 13689612 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Operator() > > > > 6.2411 > > > > 6.2411 > > > > 131146274 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Advance(int i) > > > > 5.9264 > > > > 8.7202 > > > > 66000263 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.SetOperator(int op) > > > > 5.5750 > > > > 5.5750 > > > > 131146274 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Backtrack() > > > > 5.5692 > > > > 9.4895 > > > > 37781343 > > > > IronPython.Runtime.Operations > > > > Ops.CallWithContext(ICallerContext context, object func, object > arg0, object arg1) > > > > 5.5572 > > > > 114.5245 > > > > 79754 > > > > IronPython.Runtime.Calls > > > > Method.Call(ICallerContext context, object arg0) > > > > 4.9052 > > > > 114.8251 > > > > 50886 > > > > IronPython.Runtime.Calls > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > object arg1) > > > > 4.8876 > > > > 114.8059 > > > > 50886 > > > > IronPython.Runtime.Calls > > > > Function2.Call(ICallerContext context, object arg0, object arg1) > > > > 4.6400 > > > > 114.5471 > > > > 47486 > > > > IronPython.Runtime.Operations > > > > Ops.CallWithContext(ICallerContext context, object func, object arg0) > > > > 4.2344 > > > > 114.1604 > > > > 146658 > > > > System.Text.RegularExpressions > > > > RegexBoyerMoore.Scan(string text, int index, int beglimit, int endlimit) > > > > 3.6465 > > > > 3.6465 > > > > 13678131 > > > > System.Text.RegularExpressions > > > > RegexCharClass.CharInClassRecursive(char ch, string set, int start) > > > > 3.6288 > > > > 5.7113 > > > > 31508162 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Goto(int newpos) > > > > 3.2058 > > > > 5.1470 > > > > 27364668 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Operand(int i) > > > > 3.1923 > > > > 3.1923 > > > > 73230687 > > > > System.Text.RegularExpressions > > > > RegexRunner.EnsureStorage() > > > > 3.0803 > > > > 3.0803 > > > > 51474823 > > > > System.Text.RegularExpressions > > > > RegexCharClass.CharInClass(char ch, string set) > > > > 3.0713 > > > > 8.7827 > > > > 31508162 > > > > IronPython.Runtime.Calls > > > > Method.Call(ICallerContext context, object arg0, object arg1) > > > > 2.9821 > > > > 7.8675 > > > > 15012 > > > > IronPython.Runtime.Calls > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > object arg1, object arg2) > > > > 2.9794 > > > > 7.8639 > > > > 15012 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Forwardcharnext() > > > > 2.8852 > > > > 2.8852 > > > > 62865185 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Forwardchars() > > > > 2.8279 > > > > 2.8279 > > > > 59436277 > > > > System.Text.RegularExpressions > > > > RegexCharClass.CharInClassInternal(char ch, string set, int start, > int mySetLength, int myCategoryLength) > > > > 2.0632 > > > > 2.0826 > > > > 31508162 > > > > System.Text.RegularExpressions > > > > RegexRunner.Scan(Regex regex, string text, int textbeg, int textend, > int textstart, int prevlen, bool quick) > > > > 1.8376 > > > > 101.7226 > > > > 43009 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.FindFirstChar() > > > > 1.6405 > > > > 5.3456 > > > > 13701755 > > > > IronPython.Runtime.Types > > > > OldClass.TryLookupSlot(SymbolId name, out object ret) > > > > 1.5573 > > > > 2.8124 > > > > 389516 > > > > IronPython.Runtime.Operations > > > > Ops.GetAttr(ICallerContext context, object o, SymbolId name) > > > > 1.5365 > > > > 5.3456 > > > > 558524 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Textpos() > > > > 1.4020 > > > > 1.4020 > > > > 32648926 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Advance() > > > > 1.1916 > > > > 2.9526 > > > > 13703950 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Textto(int newpos) > > > > 1.1218 > > > > 1.1218 > > > > 24120890 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPeek() > > > > 1.0579 > > > > 1.0579 > > > > 24120894 > > > > System.Text.RegularExpressions > > > > Regex.Run(bool quick, int prevlen, string input, int beginning, int > length, int startat) > > > > 0.7280 > > > > 102.4644 > > > > 43009 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPush(int I1) > > > > 0.6834 > > > > 0.6834 > > > > 13745149 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.StackPush(int I1) > > > > 0.6542 > > > > 0.6542 > > > > 13703955 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPop() > > > > 0.6068 > > > > 0.6068 > > > > 13663035 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPush() > > > > 0.6049 > > > > 0.6049 > > > > 13708230 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.StackPop() > > > > 0.5836 > > > > 0.5836 > > > > 13703956 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Bump() > > > > 0.4987 > > > > 0.4987 > > > > 10472790 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPush(int I1, int I2) > > > > 0.4864 > > > > 0.4864 > > > > 10472790 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPeek(int i) > > > > 0.4663 > > > > 0.4663 > > > > 10457859 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPop(int framesize) > > > > 0.4396 > > > > 0.4396 > > > > 10457859 > > > > > Moving up the stack of regex.Go(), most calls originate from > sgmllib's parse_starttag. > > HTH, > -Birsch > > On Thu, Feb 21, 2008 at 2:35 PM, Birsch > >> wrote: > > Thanks Michael and Dino. > > I'll prof and send update. Got a good profiler recommendation for .Net? > Meanwhile I noticed the sample site below causes BeautifulSoup to > generate quite a few [python] exceptions during __init__. Does > IronPython handle exceptions significantly slower than CPtyhon? > > Repro code is simple (just build a BeautifulSoup obj with mininova's > home page). > Here are the .py and .cs I used to time the diffs: > > *bstest.py:* > #Bypass CPython default socket implementation with IPCE/FePy > import imp, os, sys > sys.modules['socket'] = module = imp.new_module('socket') > execfile('socket.py', module.__dict__) > > from BeautifulSoup import BeautifulSoup > from urllib import urlopen > import datetime > > def getContent(url): > #Download html data > startTime = datetime.datetime.now() > print "Getting url", url > html = urlopen(url).read() > print "Time taken:", datetime.datetime.now() - startTime > > #Make soup > startTime = datetime.datetime.now() > print "Making soup..." > soup = BeautifulSoup(markup=html) > print "Time taken:", datetime.datetime.now() - startTime > > if __name__ == "__main__": > print getContent("www.mininova.org ") > > > *C#:* > using System; > using System.Collections.Generic; > using System.Text; > using IronPython.Hosting; > > namespace IronPythonBeautifulSoupTest > { > public class Program > { > public static void Main(string[] args) > { > //Init > System.Console.WriteLine("Starting..."); > DateTime start = DateTime.Now; > PythonEngine engine = new PythonEngine(); > > //Add paths: > //BeautifulSoup.py, socket.py, bstest.py located on exe dir > engine.AddToPath(@"."); > //CPython Lib (replace with your own) > engine.AddToPath(@"D:\Dev\Python\Lib"); > > //Import and load > TimeSpan span = DateTime.Now - start; > System.Console.WriteLine("[1] Import: " + > span.TotalSeconds); > DateTime d = DateTime.Now; > engine.ExecuteFile(@"bstest.py"); > span = DateTime.Now - d; > System.Console.WriteLine("[2] Load: " + span.TotalSeconds); > > //Execute > d = DateTime.Now; > engine.Execute("getContent(\"http://www.mininova.org\")"); > span = DateTime.Now - d; > System.Console.WriteLine("[3] Execute: " + > span.TotalSeconds); > span = DateTime.Now - start; > System.Console.WriteLine("Total: " + span.TotalSeconds); > > > } > } > } > > > On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland > >> > wrote: > > We've actually had this issue reported once before a long time ago - > it's a very low CodePlex ID - > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 > > We haven't had a chance to investigate the end-to-end scenario. If > someone could come up with a smaller simpler repro that'd be great. > Otherwise we haven't forgotten about it we've just had more > immediately pressing issues to work on :(. > > > -----Original Message----- > From: users-bounces at lists.ironpython.com > > > [mailto:users-bounces at lists.ironpython.com > >] On Behalf Of Michael Foord > Sent: Wednesday, February 20, 2008 5:20 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Slow Performance of CPython libs? > > Birsch wrote: > > Hi - We've been using IronPython successfully to allow extensibility > > of our application. > > > > Overall we are happy with the performance, with the exception of > > BeautifulSoup which seems to run very slowly: x5 or more time to > > execute compared to CPython. > > > > Most of the time seems to be spent during __init__() of BS, where the > > markup is parsed. > > > > We suspect this has to do with the fact that our CPython env is > > executing .pyc files and can precompile its libs, while the > IronPython > > environment compiles each iteration. We couldn't find a way to > > pre-compile the libs and then introduce them into the code, but > in any > > case this will result in a large management overhead since the amount > > of CPython libs we expose to our users contains 100's of modules. > > > > Any ideas on how to optimize? > > I think it is worth doing real profiling to find out where the time is > being spent during parsing. > > If it is spending most of the time in '__init__' then the time is > probably not spent in importing - so compilation isn't relevant and it > is a runtime performance issue. (Importing is much slower with > IronPython and at Resolver Systems we do use precompiled binaries - but > strangely enough it doesn't provide much of a performance gain.) > > Michael > http://www.manning.com/foord > > > > > Thanks, > > -Birsch > > > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 runtime DLLs > > (this was done to overcome library incompatibilities and network > > errors). However, the relevant slow .py code (mainly SGMLParser and > > BeautifulSoup) is the same. > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Fri Feb 22 19:57:09 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Fri, 22 Feb 2008 10:57:09 -0800 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <47BF149F.7040300@voidspace.org.uk> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> <1e4778de0802210830s60e4f13eue81dd421eca4677@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4EB6CCF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802211004k6a3fbdf4i79d8de7fd243c6c1@mail.gmail.com> <47BDC089.90106@houmus.org> <7AD436E4270DD54A94238001769C2227011CF4EB6D2B@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802220940t433773dek4fcd8f414232f6d6@mail.gmail.com> <47BF149F.7040300@voidspace.org.uk> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4EB702A@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Unfortunately CodePlex doesn't make it very easy to track bugs across multiple releases. If there's ever any bugs that you'd like to see fixed in 1.1.x I'd suggest opening a bug with a title of 1.1.x: . You could also include a link to the associated 2.0 bug number if there's one there. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: Friday, February 22, 2008 10:30 AM To: Discussion of IronPython Subject: Re: [IronPython] Slow Performance of CPython libs? Birsch wrote: > Dino - do you want me to register a workitem? Also, if I wanted to > patch v1.1.1, where should I start? This is a good point. As you fix bugs is it possible to at least mark which ones might be suitable to fold back into 1.1. This and the socket bugs recently discussed would be really great to see fixed in a 1.1.2 release... Thanks Michael Foord http://www.manning.com/foord > > On Thu, Feb 21, 2008 at 8:48 PM, Dino Viehland > > > wrote: > > After Birsh's last comment that they're calling compile I was > thinking we might be doing something really stupid. Turns out > that we are. For our supposedly compiled regex's we're not > passing the Compiled option. So they're all getting interpretted > and of course that's going to suck big time. > > So the fix for this is probably to just pass RegexOptions.Compiled > to the Regex object being contructed into RE_Pattern. Internally > the Regex class will compile to dynamic methods (much better than > compiling to an assembly because it'll be collectible). > > It's actually a little more complex than that because we create > RE_Pattern objects for the non-compiled so we need to flow the > option in, but it's still a simple fix. > > -----Original Message----- > From: users-bounces at lists.ironpython.com > > [mailto:users-bounces at lists.ironpython.com > ] On Behalf Of Dan Shechter > Sent: Thursday, February 21, 2008 10:19 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Slow Performance of CPython libs? > > Just out of curiosity... > I'm guessing that there are two levels of caching that could be used. > One would be to hold a global dictionary of some sort of pattern -> > Regex that will save the lengthy parsing of the re. > > The other would be to actually call Regex.CompileToAssembly to get a > more efficient reperesentation (in runtime that is) of the re. > > Would you (the IP team) favor the former or the latter? > > Shechter. > > > Birsch wrote: > > I checked both sgmllib.py and BeautifulSoup.py - and it seems > both are > > reusing the same regexps (searched for re.compile). > > > > I think your suggestion is very relevant in this case. It makes > sense to > > replicate the "compile once use many" behavior that is commonly used > > with regexp. > > > > -Birsch > > > > On Thu, Feb 21, 2008 at 7:30 PM, Dino Viehland > > > >> wrote: > > > > Do you know if the same reg ex is being used repeatedly? If so > > maybe we can cache & compile the regex instead of > interpretting it > > all the time. > > > > > > > > *From:* users-bounces at lists.ironpython.com > > > > > > [mailto:users-bounces at lists.ironpython.com > > > >] *On Behalf Of *Birsch > > *Sent:* Thursday, February 21, 2008 8:30 AM > > > > *To:* Discussion of IronPython > > *Subject:* Re: [IronPython] Slow Performance of CPython libs? > > > > > > > > I took on Cooper's advice and profiled with ANTS. Here are > the top > > methods: > > > > *Namespace* > > > > > > > > *Method name* > > > > > > > > *Time (sec.)* > > > > > > > > *Time with children (sec.)* > > > > > > > > *Hit count* > > > > > > > > *Source file* > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Go() > > > > > > > > 37.0189 > > > > > > > > 94.4676 > > > > > > > > 13689612 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Operator() > > > > > > > > 6.2411 > > > > > > > > 6.2411 > > > > > > > > 131146274 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Advance(int i) > > > > > > > > 5.9264 > > > > > > > > 8.7202 > > > > > > > > 66000263 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.SetOperator(int op) > > > > > > > > 5.5750 > > > > > > > > 5.5750 > > > > > > > > 131146274 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Backtrack() > > > > > > > > 5.5692 > > > > > > > > 9.4895 > > > > > > > > 37781343 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.CallWithContext(ICallerContext context, object func, object > > arg0, object arg1) > > > > > > > > 5.5572 > > > > > > > > 114.5245 > > > > > > > > 79754 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Method.Call(ICallerContext context, object arg0) > > > > > > > > 4.9052 > > > > > > > > 114.8251 > > > > > > > > 50886 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > > object arg1) > > > > > > > > 4.8876 > > > > > > > > 114.8059 > > > > > > > > 50886 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Function2.Call(ICallerContext context, object arg0, object arg1) > > > > > > > > 4.6400 > > > > > > > > 114.5471 > > > > > > > > 47486 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.CallWithContext(ICallerContext context, object func, > object arg0) > > > > > > > > 4.2344 > > > > > > > > 114.1604 > > > > > > > > 146658 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexBoyerMoore.Scan(string text, int index, int beglimit, > int endlimit) > > > > > > > > 3.6465 > > > > > > > > 3.6465 > > > > > > > > 13678131 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClassRecursive(char ch, string set, int > start) > > > > > > > > 3.6288 > > > > > > > > 5.7113 > > > > > > > > 31508162 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Goto(int newpos) > > > > > > > > 3.2058 > > > > > > > > 5.1470 > > > > > > > > 27364668 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Operand(int i) > > > > > > > > 3.1923 > > > > > > > > 3.1923 > > > > > > > > 73230687 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexRunner.EnsureStorage() > > > > > > > > 3.0803 > > > > > > > > 3.0803 > > > > > > > > 51474823 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClass(char ch, string set) > > > > > > > > 3.0713 > > > > > > > > 8.7827 > > > > > > > > 31508162 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Method.Call(ICallerContext context, object arg0, object arg1) > > > > > > > > 2.9821 > > > > > > > > 7.8675 > > > > > > > > 15012 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > > object arg1, object arg2) > > > > > > > > 2.9794 > > > > > > > > 7.8639 > > > > > > > > 15012 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Forwardcharnext() > > > > > > > > 2.8852 > > > > > > > > 2.8852 > > > > > > > > 62865185 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Forwardchars() > > > > > > > > 2.8279 > > > > > > > > 2.8279 > > > > > > > > 59436277 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClassInternal(char ch, string set, int > start, > > int mySetLength, int myCategoryLength) > > > > > > > > 2.0632 > > > > > > > > 2.0826 > > > > > > > > 31508162 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexRunner.Scan(Regex regex, string text, int textbeg, int > textend, > > int textstart, int prevlen, bool quick) > > > > > > > > 1.8376 > > > > > > > > 101.7226 > > > > > > > > 43009 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.FindFirstChar() > > > > > > > > 1.6405 > > > > > > > > 5.3456 > > > > > > > > 13701755 > > > > > > > > IronPython.Runtime.Types > > > > > > > > OldClass.TryLookupSlot(SymbolId name, out object ret) > > > > > > > > 1.5573 > > > > > > > > 2.8124 > > > > > > > > 389516 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.GetAttr(ICallerContext context, object o, SymbolId name) > > > > > > > > 1.5365 > > > > > > > > 5.3456 > > > > > > > > 558524 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Textpos() > > > > > > > > 1.4020 > > > > > > > > 1.4020 > > > > > > > > 32648926 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Advance() > > > > > > > > 1.1916 > > > > > > > > 2.9526 > > > > > > > > 13703950 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Textto(int newpos) > > > > > > > > 1.1218 > > > > > > > > 1.1218 > > > > > > > > 24120890 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPeek() > > > > > > > > 1.0579 > > > > > > > > 1.0579 > > > > > > > > 24120894 > > > > > > > > System.Text.RegularExpressions > > > > > > > > Regex.Run(bool quick, int prevlen, string input, int > beginning, int > > length, int startat) > > > > > > > > 0.7280 > > > > > > > > 102.4644 > > > > > > > > 43009 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush(int I1) > > > > > > > > 0.6834 > > > > > > > > 0.6834 > > > > > > > > 13745149 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.StackPush(int I1) > > > > > > > > 0.6542 > > > > > > > > 0.6542 > > > > > > > > 13703955 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPop() > > > > > > > > 0.6068 > > > > > > > > 0.6068 > > > > > > > > 13663035 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush() > > > > > > > > 0.6049 > > > > > > > > 0.6049 > > > > > > > > 13708230 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.StackPop() > > > > > > > > 0.5836 > > > > > > > > 0.5836 > > > > > > > > 13703956 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Bump() > > > > > > > > 0.4987 > > > > > > > > 0.4987 > > > > > > > > 10472790 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush(int I1, int I2) > > > > > > > > 0.4864 > > > > > > > > 0.4864 > > > > > > > > 10472790 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPeek(int i) > > > > > > > > 0.4663 > > > > > > > > 0.4663 > > > > > > > > 10457859 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPop(int framesize) > > > > > > > > 0.4396 > > > > > > > > 0.4396 > > > > > > > > 10457859 > > > > > > > > > > Moving up the stack of regex.Go(), most calls originate from > > sgmllib's parse_starttag. > > > > HTH, > > -Birsch > > > > On Thu, Feb 21, 2008 at 2:35 PM, Birsch > > >> wrote: > > > > Thanks Michael and Dino. > > > > I'll prof and send update. Got a good profiler > recommendation for .Net? > > Meanwhile I noticed the sample site below causes > BeautifulSoup to > > generate quite a few [python] exceptions during __init__. Does > > IronPython handle exceptions significantly slower than CPtyhon? > > > > Repro code is simple (just build a BeautifulSoup obj with > mininova's > > home page). > > Here are the .py and .cs I used to time the diffs: > > > > *bstest.py:* > > #Bypass CPython default socket implementation with IPCE/FePy > > import imp, os, sys > > sys.modules['socket'] = module = imp.new_module('socket') > > execfile('socket.py', module.__dict__) > > > > from BeautifulSoup import BeautifulSoup > > from urllib import urlopen > > import datetime > > > > def getContent(url): > > #Download html data > > startTime = datetime.datetime.now() > > print "Getting url", url > > html = urlopen(url).read() > > print "Time taken:", datetime.datetime.now() - startTime > > > > #Make soup > > startTime = datetime.datetime.now() > > print "Making soup..." > > soup = BeautifulSoup(markup=html) > > print "Time taken:", datetime.datetime.now() - startTime > > > > if __name__ == "__main__": > > print getContent("www.mininova.org > ") > > > > > > *C#:* > > using System; > > using System.Collections.Generic; > > using System.Text; > > using IronPython.Hosting; > > > > namespace IronPythonBeautifulSoupTest > > { > > public class Program > > { > > public static void Main(string[] args) > > { > > //Init > > System.Console.WriteLine("Starting..."); > > DateTime start = DateTime.Now; > > PythonEngine engine = new PythonEngine(); > > > > //Add paths: > > //BeautifulSoup.py, socket.py, bstest.py located > on exe dir > > engine.AddToPath(@"."); > > //CPython Lib (replace with your own) > > engine.AddToPath(@"D:\Dev\Python\Lib"); > > > > //Import and load > > TimeSpan span = DateTime.Now - start; > > System.Console.WriteLine("[1] Import: " + > > span.TotalSeconds); > > DateTime d = DateTime.Now; > > engine.ExecuteFile(@"bstest.py"); > > span = DateTime.Now - d; > > System.Console.WriteLine("[2] Load: " + > span.TotalSeconds); > > > > //Execute > > d = DateTime.Now; > > > engine.Execute("getContent(\"http://www.mininova.org\ > ")"); > > span = DateTime.Now - d; > > System.Console.WriteLine("[3] Execute: " + > > span.TotalSeconds); > > span = DateTime.Now - start; > > System.Console.WriteLine("Total: " + > span.TotalSeconds); > > > > > > } > > } > > } > > > > > > On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland > > > >> > > wrote: > > > > We've actually had this issue reported once before a long > time ago - > > it's a very low CodePlex ID - > > > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 > > > > We haven't had a chance to investigate the end-to-end > scenario. If > > someone could come up with a smaller simpler repro that'd be > great. > > Otherwise we haven't forgotten about it we've just had more > > immediately pressing issues to work on :(. > > > > > > -----Original Message----- > > From: users-bounces at lists.ironpython.com > > > > > > [mailto:users-bounces at lists.ironpython.com > > > >] On Behalf Of Michael > Foord > > Sent: Wednesday, February 20, 2008 5:20 AM > > To: Discussion of IronPython > > Subject: Re: [IronPython] Slow Performance of CPython libs? > > > > Birsch wrote: > > > Hi - We've been using IronPython successfully to allow > extensibility > > > of our application. > > > > > > Overall we are happy with the performance, with the > exception of > > > BeautifulSoup which seems to run very slowly: x5 or more > time to > > > execute compared to CPython. > > > > > > Most of the time seems to be spent during __init__() of > BS, where the > > > markup is parsed. > > > > > > We suspect this has to do with the fact that our CPython > env is > > > executing .pyc files and can precompile its libs, while the > > IronPython > > > environment compiles each iteration. We couldn't find a > way to > > > pre-compile the libs and then introduce them into the > code, but > > in any > > > case this will result in a large management overhead > since the amount > > > of CPython libs we expose to our users contains 100's of > modules. > > > > > > Any ideas on how to optimize? > > > > I think it is worth doing real profiling to find out where > the time is > > being spent during parsing. > > > > If it is spending most of the time in '__init__' then the > time is > > probably not spent in importing - so compilation isn't > relevant and it > > is a runtime performance issue. (Importing is much slower with > > IronPython and at Resolver Systems we do use precompiled > binaries - but > > strangely enough it doesn't provide much of a performance gain.) > > > > Michael > > http://www.manning.com/foord > > > > > > > > Thanks, > > > -Birsch > > > > > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 > runtime DLLs > > > (this was done to overcome library incompatibilities and > network > > > errors). However, the relevant slow .py code (mainly > SGMLParser and > > > BeautifulSoup) is the same. > > > > > > ------------------------------------------------------------------------ > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From dinov at exchange.microsoft.com Fri Feb 22 20:03:50 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Fri, 22 Feb 2008 11:03:50 -0800 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <1e4778de0802220940t433773dek4fcd8f414232f6d6@mail.gmail.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <47BC28F2.1020009@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> <1e4778de0802210830s60e4f13eue81dd421eca4677@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4EB6CCF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802211004k6a3fbdf4i79d8de7fd243c6c1@mail.gmail.com> <47BDC089.90106@houmus.org> <7AD436E4270DD54A94238001769C2227011CF4EB6D2B@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802220940t433773dek4fcd8f414232f6d6@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF4EB7035@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Oh, and I've gone ahead and created a bug for this one for 2.0: http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=15289 From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Birsch Sent: Friday, February 22, 2008 9:40 AM To: Discussion of IronPython Subject: Re: [IronPython] Slow Performance of CPython libs? Dino - do you want me to register a workitem? Also, if I wanted to patch v1.1.1, where should I start? On Thu, Feb 21, 2008 at 8:48 PM, Dino Viehland > wrote: After Birsh's last comment that they're calling compile I was thinking we might be doing something really stupid. Turns out that we are. For our supposedly compiled regex's we're not passing the Compiled option. So they're all getting interpretted and of course that's going to suck big time. So the fix for this is probably to just pass RegexOptions.Compiled to the Regex object being contructed into RE_Pattern. Internally the Regex class will compile to dynamic methods (much better than compiling to an assembly because it'll be collectible). It's actually a little more complex than that because we create RE_Pattern objects for the non-compiled so we need to flow the option in, but it's still a simple fix. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dan Shechter Sent: Thursday, February 21, 2008 10:19 AM To: Discussion of IronPython Subject: Re: [IronPython] Slow Performance of CPython libs? Just out of curiosity... I'm guessing that there are two levels of caching that could be used. One would be to hold a global dictionary of some sort of pattern -> Regex that will save the lengthy parsing of the re. The other would be to actually call Regex.CompileToAssembly to get a more efficient reperesentation (in runtime that is) of the re. Would you (the IP team) favor the former or the latter? Shechter. Birsch wrote: > I checked both sgmllib.py and BeautifulSoup.py - and it seems both are > reusing the same regexps (searched for re.compile). > > I think your suggestion is very relevant in this case. It makes sense to > replicate the "compile once use many" behavior that is commonly used > with regexp. > > -Birsch > > On Thu, Feb 21, 2008 at 7:30 PM, Dino Viehland > >> wrote: > > Do you know if the same reg ex is being used repeatedly? If so > maybe we can cache & compile the regex instead of interpretting it > all the time. > > > > *From:* users-bounces at lists.ironpython.com > > > [mailto:users-bounces at lists.ironpython.com > >] *On Behalf Of *Birsch > *Sent:* Thursday, February 21, 2008 8:30 AM > > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] Slow Performance of CPython libs? > > > > I took on Cooper's advice and profiled with ANTS. Here are the top > methods: > > *Namespace* > > > > *Method name* > > > > *Time (sec.)* > > > > *Time with children (sec.)* > > > > *Hit count* > > > > *Source file* > > System.Text.RegularExpressions > > > > RegexInterpreter.Go() > > > > 37.0189 > > > > 94.4676 > > > > 13689612 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Operator() > > > > 6.2411 > > > > 6.2411 > > > > 131146274 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Advance(int i) > > > > 5.9264 > > > > 8.7202 > > > > 66000263 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.SetOperator(int op) > > > > 5.5750 > > > > 5.5750 > > > > 131146274 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Backtrack() > > > > 5.5692 > > > > 9.4895 > > > > 37781343 > > > > IronPython.Runtime.Operations > > > > Ops.CallWithContext(ICallerContext context, object func, object > arg0, object arg1) > > > > 5.5572 > > > > 114.5245 > > > > 79754 > > > > IronPython.Runtime.Calls > > > > Method.Call(ICallerContext context, object arg0) > > > > 4.9052 > > > > 114.8251 > > > > 50886 > > > > IronPython.Runtime.Calls > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > object arg1) > > > > 4.8876 > > > > 114.8059 > > > > 50886 > > > > IronPython.Runtime.Calls > > > > Function2.Call(ICallerContext context, object arg0, object arg1) > > > > 4.6400 > > > > 114.5471 > > > > 47486 > > > > IronPython.Runtime.Operations > > > > Ops.CallWithContext(ICallerContext context, object func, object arg0) > > > > 4.2344 > > > > 114.1604 > > > > 146658 > > > > System.Text.RegularExpressions > > > > RegexBoyerMoore.Scan(string text, int index, int beglimit, int endlimit) > > > > 3.6465 > > > > 3.6465 > > > > 13678131 > > > > System.Text.RegularExpressions > > > > RegexCharClass.CharInClassRecursive(char ch, string set, int start) > > > > 3.6288 > > > > 5.7113 > > > > 31508162 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Goto(int newpos) > > > > 3.2058 > > > > 5.1470 > > > > 27364668 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Operand(int i) > > > > 3.1923 > > > > 3.1923 > > > > 73230687 > > > > System.Text.RegularExpressions > > > > RegexRunner.EnsureStorage() > > > > 3.0803 > > > > 3.0803 > > > > 51474823 > > > > System.Text.RegularExpressions > > > > RegexCharClass.CharInClass(char ch, string set) > > > > 3.0713 > > > > 8.7827 > > > > 31508162 > > > > IronPython.Runtime.Calls > > > > Method.Call(ICallerContext context, object arg0, object arg1) > > > > 2.9821 > > > > 7.8675 > > > > 15012 > > > > IronPython.Runtime.Calls > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > object arg1, object arg2) > > > > 2.9794 > > > > 7.8639 > > > > 15012 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Forwardcharnext() > > > > 2.8852 > > > > 2.8852 > > > > 62865185 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Forwardchars() > > > > 2.8279 > > > > 2.8279 > > > > 59436277 > > > > System.Text.RegularExpressions > > > > RegexCharClass.CharInClassInternal(char ch, string set, int start, > int mySetLength, int myCategoryLength) > > > > 2.0632 > > > > 2.0826 > > > > 31508162 > > > > System.Text.RegularExpressions > > > > RegexRunner.Scan(Regex regex, string text, int textbeg, int textend, > int textstart, int prevlen, bool quick) > > > > 1.8376 > > > > 101.7226 > > > > 43009 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.FindFirstChar() > > > > 1.6405 > > > > 5.3456 > > > > 13701755 > > > > IronPython.Runtime.Types > > > > OldClass.TryLookupSlot(SymbolId name, out object ret) > > > > 1.5573 > > > > 2.8124 > > > > 389516 > > > > IronPython.Runtime.Operations > > > > Ops.GetAttr(ICallerContext context, object o, SymbolId name) > > > > 1.5365 > > > > 5.3456 > > > > 558524 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Textpos() > > > > 1.4020 > > > > 1.4020 > > > > 32648926 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Advance() > > > > 1.1916 > > > > 2.9526 > > > > 13703950 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Textto(int newpos) > > > > 1.1218 > > > > 1.1218 > > > > 24120890 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPeek() > > > > 1.0579 > > > > 1.0579 > > > > 24120894 > > > > System.Text.RegularExpressions > > > > Regex.Run(bool quick, int prevlen, string input, int beginning, int > length, int startat) > > > > 0.7280 > > > > 102.4644 > > > > 43009 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPush(int I1) > > > > 0.6834 > > > > 0.6834 > > > > 13745149 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.StackPush(int I1) > > > > 0.6542 > > > > 0.6542 > > > > 13703955 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPop() > > > > 0.6068 > > > > 0.6068 > > > > 13663035 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPush() > > > > 0.6049 > > > > 0.6049 > > > > 13708230 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.StackPop() > > > > 0.5836 > > > > 0.5836 > > > > 13703956 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.Bump() > > > > 0.4987 > > > > 0.4987 > > > > 10472790 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPush(int I1, int I2) > > > > 0.4864 > > > > 0.4864 > > > > 10472790 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPeek(int i) > > > > 0.4663 > > > > 0.4663 > > > > 10457859 > > > > System.Text.RegularExpressions > > > > RegexInterpreter.TrackPop(int framesize) > > > > 0.4396 > > > > 0.4396 > > > > 10457859 > > > > > Moving up the stack of regex.Go(), most calls originate from > sgmllib's parse_starttag. > > HTH, > -Birsch > > On Thu, Feb 21, 2008 at 2:35 PM, Birsch > >> wrote: > > Thanks Michael and Dino. > > I'll prof and send update. Got a good profiler recommendation for .Net? > Meanwhile I noticed the sample site below causes BeautifulSoup to > generate quite a few [python] exceptions during __init__. Does > IronPython handle exceptions significantly slower than CPtyhon? > > Repro code is simple (just build a BeautifulSoup obj with mininova's > home page). > Here are the .py and .cs I used to time the diffs: > > *bstest.py:* > #Bypass CPython default socket implementation with IPCE/FePy > import imp, os, sys > sys.modules['socket'] = module = imp.new_module('socket') > execfile('socket.py', module.__dict__) > > from BeautifulSoup import BeautifulSoup > from urllib import urlopen > import datetime > > def getContent(url): > #Download html data > startTime = datetime.datetime.now() > print "Getting url", url > html = urlopen(url).read() > print "Time taken:", datetime.datetime.now() - startTime > > #Make soup > startTime = datetime.datetime.now() > print "Making soup..." > soup = BeautifulSoup(markup=html) > print "Time taken:", datetime.datetime.now() - startTime > > if __name__ == "__main__": > print getContent("www.mininova.org ") > > > *C#:* > using System; > using System.Collections.Generic; > using System.Text; > using IronPython.Hosting; > > namespace IronPythonBeautifulSoupTest > { > public class Program > { > public static void Main(string[] args) > { > //Init > System.Console.WriteLine("Starting..."); > DateTime start = DateTime.Now; > PythonEngine engine = new PythonEngine(); > > //Add paths: > //BeautifulSoup.py, socket.py, bstest.py located on exe dir > engine.AddToPath(@"."); > //CPython Lib (replace with your own) > engine.AddToPath(@"D:\Dev\Python\Lib"); > > //Import and load > TimeSpan span = DateTime.Now - start; > System.Console.WriteLine("[1] Import: " + > span.TotalSeconds); > DateTime d = DateTime.Now; > engine.ExecuteFile(@"bstest.py"); > span = DateTime.Now - d; > System.Console.WriteLine("[2] Load: " + span.TotalSeconds); > > //Execute > d = DateTime.Now; > engine.Execute("getContent(\"http://www.mininova.org\")"); > span = DateTime.Now - d; > System.Console.WriteLine("[3] Execute: " + > span.TotalSeconds); > span = DateTime.Now - start; > System.Console.WriteLine("Total: " + span.TotalSeconds); > > > } > } > } > > > On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland > >> > wrote: > > We've actually had this issue reported once before a long time ago - > it's a very low CodePlex ID - > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 > > We haven't had a chance to investigate the end-to-end scenario. If > someone could come up with a smaller simpler repro that'd be great. > Otherwise we haven't forgotten about it we've just had more > immediately pressing issues to work on :(. > > > -----Original Message----- > From: users-bounces at lists.ironpython.com > > > [mailto:users-bounces at lists.ironpython.com > >] On Behalf Of Michael Foord > Sent: Wednesday, February 20, 2008 5:20 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Slow Performance of CPython libs? > > Birsch wrote: > > Hi - We've been using IronPython successfully to allow extensibility > > of our application. > > > > Overall we are happy with the performance, with the exception of > > BeautifulSoup which seems to run very slowly: x5 or more time to > > execute compared to CPython. > > > > Most of the time seems to be spent during __init__() of BS, where the > > markup is parsed. > > > > We suspect this has to do with the fact that our CPython env is > > executing .pyc files and can precompile its libs, while the > IronPython > > environment compiles each iteration. We couldn't find a way to > > pre-compile the libs and then introduce them into the code, but > in any > > case this will result in a large management overhead since the amount > > of CPython libs we expose to our users contains 100's of modules. > > > > Any ideas on how to optimize? > > I think it is worth doing real profiling to find out where the time is > being spent during parsing. > > If it is spending most of the time in '__init__' then the time is > probably not spent in importing - so compilation isn't relevant and it > is a runtime performance issue. (Importing is much slower with > IronPython and at Resolver Systems we do use precompiled binaries - but > strangely enough it doesn't provide much of a performance gain.) > > Michael > http://www.manning.com/foord > > > > > Thanks, > > -Birsch > > > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 runtime DLLs > > (this was done to overcome library incompatibilities and network > > errors). However, the relevant slow .py code (mainly SGMLParser and > > BeautifulSoup) is the same. > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From william at resolversystems.com Fri Feb 22 20:05:08 2008 From: william at resolversystems.com (William Reade) Date: Fri, 22 Feb 2008 19:05:08 +0000 Subject: [IronPython] Announcement: Ironclad v0.1 Message-ID: <47BF1CE4.3060400@resolversystems.com> Hi all I'm delighted to announce that Ironclad 0.1, our nascent CPython compatibility library, is now available at: http://code.google.com/p/ironclad/downloads/list It's not very impressive yet, and it's still win32-only, but it will import the bz2.pyd module from CPython 2.5; the compress() and decompress() functions should work, as should the BZ2Compressor and BZ2Decompressor types. Sadly, BZ2File still needs quite a lot of work. Nonetheless, please download it and have a play :-). Be aware that you can't just reference the DLLs and have everything Just Work -- have a look in 'tests/functionalitytest.py' to see how to make it work; have a look at 'doc/details.txt' if you're interested in what's going on under the hood. Bug reports, complaints, advice and patches are all very welcome; of course, bug reports with integrated patches and test cases will receive the maximum possible brownie points ;-). Cheers William -- William Reade Resolver Systems william at resolversystems.com We're hiring! http://www.resolversystems.com/jobs/ Office address: 17a Clerkenwell Road, London EC1M 5RD, UK Registered address: 843 Finchley Road, London NW11 8NA, UK Resolver Systems Limited is registered in England and Wales as company number 5467329. From SomethingNew2_0 at hotmail.com Fri Feb 22 21:20:40 2008 From: SomethingNew2_0 at hotmail.com (Herny Johnson) Date: Fri, 22 Feb 2008 14:20:40 -0600 Subject: [IronPython] .NET Arrays Message-ID: When I'm trying to add .NET Arrays that are holding one type of object with the System.Array.Add function. I get an error that the says "expected object with __len__ function, got Texture2D (whatever objects that I want to merge). I'm using Xna as you might have guessed. I just want to add the objects into one array, not add the objects together. How do I do this? -------------- next part -------------- An HTML attachment was scrubbed... URL: From birsch at gmail.com Fri Feb 22 21:24:17 2008 From: birsch at gmail.com (Birsch) Date: Fri, 22 Feb 2008 22:24:17 +0200 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF4EB7035@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4D277B6@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> <1e4778de0802210830s60e4f13eue81dd421eca4677@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4EB6CCF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802211004k6a3fbdf4i79d8de7fd243c6c1@mail.gmail.com> <47BDC089.90106@houmus.org> <7AD436E4270DD54A94238001769C2227011CF4EB6D2B@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802220940t433773dek4fcd8f414232f6d6@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4EB7035@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <1e4778de0802221224i7ccc2386u99a04761d64515b4@mail.gmail.com> Great, you've got my vote :) Thanks a lot for your help. On Fri, Feb 22, 2008 at 9:03 PM, Dino Viehland wrote: > Oh, and I've gone ahead and created a bug for this one for 2.0: > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=15289 > > > > *From:* users-bounces at lists.ironpython.com [mailto: > users-bounces at lists.ironpython.com] *On Behalf Of *Birsch > *Sent:* Friday, February 22, 2008 9:40 AM > > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] Slow Performance of CPython libs? > > > > Dino - do you want me to register a workitem? Also, if I wanted to patch > v1.1.1, where should I start? > > On Thu, Feb 21, 2008 at 8:48 PM, Dino Viehland < > dinov at exchange.microsoft.com> wrote: > > After Birsh's last comment that they're calling compile I was thinking we > might be doing something really stupid. Turns out that we are. For our > supposedly compiled regex's we're not passing the Compiled option. So > they're all getting interpretted and of course that's going to suck big > time. > > So the fix for this is probably to just pass RegexOptions.Compiled to the > Regex object being contructed into RE_Pattern. Internally the Regex class > will compile to dynamic methods (much better than compiling to an assembly > because it'll be collectible). > > It's actually a little more complex than that because we create RE_Pattern > objects for the non-compiled so we need to flow the option in, but it's > still a simple fix. > > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto: > users-bounces at lists.ironpython.com] On Behalf Of Dan Shechter > Sent: Thursday, February 21, 2008 10:19 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Slow Performance of CPython libs? > > Just out of curiosity... > I'm guessing that there are two levels of caching that could be used. > One would be to hold a global dictionary of some sort of pattern -> > Regex that will save the lengthy parsing of the re. > > The other would be to actually call Regex.CompileToAssembly to get a > more efficient reperesentation (in runtime that is) of the re. > > Would you (the IP team) favor the former or the latter? > > Shechter. > > > Birsch wrote: > > I checked both sgmllib.py and BeautifulSoup.py - and it seems both are > > reusing the same regexps (searched for re.compile). > > > > I think your suggestion is very relevant in this case. It makes sense to > > replicate the "compile once use many" behavior that is commonly used > > with regexp. > > > > -Birsch > > > > On Thu, Feb 21, 2008 at 7:30 PM, Dino Viehland > > > > wrote: > > > > Do you know if the same reg ex is being used repeatedly? If so > > maybe we can cache & compile the regex instead of interpretting it > > all the time. > > > > > > > > *From:* users-bounces at lists.ironpython.com > > > > [mailto:users-bounces at lists.ironpython.com > > ] *On Behalf Of *Birsch > > *Sent:* Thursday, February 21, 2008 8:30 AM > > > > *To:* Discussion of IronPython > > *Subject:* Re: [IronPython] Slow Performance of CPython libs? > > > > > > > > I took on Cooper's advice and profiled with ANTS. Here are the top > > methods: > > > > *Namespace* > > > > > > > > *Method name* > > > > > > > > *Time (sec.)* > > > > > > > > *Time with children (sec.)* > > > > > > > > *Hit count* > > > > > > > > *Source file* > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Go() > > > > > > > > 37.0189 > > > > > > > > 94.4676 > > > > > > > > 13689612 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Operator() > > > > > > > > 6.2411 > > > > > > > > 6.2411 > > > > > > > > 131146274 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Advance(int i) > > > > > > > > 5.9264 > > > > > > > > 8.7202 > > > > > > > > 66000263 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.SetOperator(int op) > > > > > > > > 5.5750 > > > > > > > > 5.5750 > > > > > > > > 131146274 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Backtrack() > > > > > > > > 5.5692 > > > > > > > > 9.4895 > > > > > > > > 37781343 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.CallWithContext(ICallerContext context, object func, object > > arg0, object arg1) > > > > > > > > 5.5572 > > > > > > > > 114.5245 > > > > > > > > 79754 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Method.Call(ICallerContext context, object arg0) > > > > > > > > 4.9052 > > > > > > > > 114.8251 > > > > > > > > 50886 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > > object arg1) > > > > > > > > 4.8876 > > > > > > > > 114.8059 > > > > > > > > 50886 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Function2.Call(ICallerContext context, object arg0, object arg1) > > > > > > > > 4.6400 > > > > > > > > 114.5471 > > > > > > > > 47486 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.CallWithContext(ICallerContext context, object func, object > arg0) > > > > > > > > 4.2344 > > > > > > > > 114.1604 > > > > > > > > 146658 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexBoyerMoore.Scan(string text, int index, int beglimit, int > endlimit) > > > > > > > > 3.6465 > > > > > > > > 3.6465 > > > > > > > > 13678131 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClassRecursive(char ch, string set, int start) > > > > > > > > 3.6288 > > > > > > > > 5.7113 > > > > > > > > 31508162 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Goto(int newpos) > > > > > > > > 3.2058 > > > > > > > > 5.1470 > > > > > > > > 27364668 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Operand(int i) > > > > > > > > 3.1923 > > > > > > > > 3.1923 > > > > > > > > 73230687 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexRunner.EnsureStorage() > > > > > > > > 3.0803 > > > > > > > > 3.0803 > > > > > > > > 51474823 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClass(char ch, string set) > > > > > > > > 3.0713 > > > > > > > > 8.7827 > > > > > > > > 31508162 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Method.Call(ICallerContext context, object arg0, object arg1) > > > > > > > > 2.9821 > > > > > > > > 7.8675 > > > > > > > > 15012 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > > object arg1, object arg2) > > > > > > > > 2.9794 > > > > > > > > 7.8639 > > > > > > > > 15012 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Forwardcharnext() > > > > > > > > 2.8852 > > > > > > > > 2.8852 > > > > > > > > 62865185 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Forwardchars() > > > > > > > > 2.8279 > > > > > > > > 2.8279 > > > > > > > > 59436277 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClassInternal(char ch, string set, int start, > > int mySetLength, int myCategoryLength) > > > > > > > > 2.0632 > > > > > > > > 2.0826 > > > > > > > > 31508162 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexRunner.Scan(Regex regex, string text, int textbeg, int textend, > > int textstart, int prevlen, bool quick) > > > > > > > > 1.8376 > > > > > > > > 101.7226 > > > > > > > > 43009 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.FindFirstChar() > > > > > > > > 1.6405 > > > > > > > > 5.3456 > > > > > > > > 13701755 > > > > > > > > IronPython.Runtime.Types > > > > > > > > OldClass.TryLookupSlot(SymbolId name, out object ret) > > > > > > > > 1.5573 > > > > > > > > 2.8124 > > > > > > > > 389516 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.GetAttr(ICallerContext context, object o, SymbolId name) > > > > > > > > 1.5365 > > > > > > > > 5.3456 > > > > > > > > 558524 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Textpos() > > > > > > > > 1.4020 > > > > > > > > 1.4020 > > > > > > > > 32648926 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Advance() > > > > > > > > 1.1916 > > > > > > > > 2.9526 > > > > > > > > 13703950 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Textto(int newpos) > > > > > > > > 1.1218 > > > > > > > > 1.1218 > > > > > > > > 24120890 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPeek() > > > > > > > > 1.0579 > > > > > > > > 1.0579 > > > > > > > > 24120894 > > > > > > > > System.Text.RegularExpressions > > > > > > > > Regex.Run(bool quick, int prevlen, string input, int beginning, int > > length, int startat) > > > > > > > > 0.7280 > > > > > > > > 102.4644 > > > > > > > > 43009 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush(int I1) > > > > > > > > 0.6834 > > > > > > > > 0.6834 > > > > > > > > 13745149 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.StackPush(int I1) > > > > > > > > 0.6542 > > > > > > > > 0.6542 > > > > > > > > 13703955 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPop() > > > > > > > > 0.6068 > > > > > > > > 0.6068 > > > > > > > > 13663035 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush() > > > > > > > > 0.6049 > > > > > > > > 0.6049 > > > > > > > > 13708230 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.StackPop() > > > > > > > > 0.5836 > > > > > > > > 0.5836 > > > > > > > > 13703956 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Bump() > > > > > > > > 0.4987 > > > > > > > > 0.4987 > > > > > > > > 10472790 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush(int I1, int I2) > > > > > > > > 0.4864 > > > > > > > > 0.4864 > > > > > > > > 10472790 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPeek(int i) > > > > > > > > 0.4663 > > > > > > > > 0.4663 > > > > > > > > 10457859 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPop(int framesize) > > > > > > > > 0.4396 > > > > > > > > 0.4396 > > > > > > > > 10457859 > > > > > > > > > > Moving up the stack of regex.Go(), most calls originate from > > sgmllib's parse_starttag. > > > > HTH, > > -Birsch > > > > On Thu, Feb 21, 2008 at 2:35 PM, Birsch > > wrote: > > > > Thanks Michael and Dino. > > > > I'll prof and send update. Got a good profiler recommendation for > .Net? > > Meanwhile I noticed the sample site below causes BeautifulSoup to > > generate quite a few [python] exceptions during __init__. Does > > IronPython handle exceptions significantly slower than CPtyhon? > > > > Repro code is simple (just build a BeautifulSoup obj with mininova's > > home page). > > Here are the .py and .cs I used to time the diffs: > > > > *bstest.py:* > > #Bypass CPython default socket implementation with IPCE/FePy > > import imp, os, sys > > sys.modules['socket'] = module = imp.new_module('socket') > > execfile('socket.py', module.__dict__) > > > > from BeautifulSoup import BeautifulSoup > > from urllib import urlopen > > import datetime > > > > def getContent(url): > > #Download html data > > startTime = datetime.datetime.now() > > print "Getting url", url > > html = urlopen(url).read() > > print "Time taken:", datetime.datetime.now() - startTime > > > > #Make soup > > startTime = datetime.datetime.now() > > print "Making soup..." > > soup = BeautifulSoup(markup=html) > > print "Time taken:", datetime.datetime.now() - startTime > > > > if __name__ == "__main__": > > print getContent("www.mininova.org ") > > > > > > *C#:* > > using System; > > using System.Collections.Generic; > > using System.Text; > > using IronPython.Hosting; > > > > namespace IronPythonBeautifulSoupTest > > { > > public class Program > > { > > public static void Main(string[] args) > > { > > //Init > > System.Console.WriteLine("Starting..."); > > DateTime start = DateTime.Now; > > PythonEngine engine = new PythonEngine(); > > > > //Add paths: > > //BeautifulSoup.py, socket.py, bstest.py located on exe > dir > > engine.AddToPath(@"."); > > //CPython Lib (replace with your own) > > engine.AddToPath(@"D:\Dev\Python\Lib"); > > > > //Import and load > > TimeSpan span = DateTime.Now - start; > > System.Console.WriteLine("[1] Import: " + > > span.TotalSeconds); > > DateTime d = DateTime.Now; > > engine.ExecuteFile(@"bstest.py"); > > span = DateTime.Now - d; > > System.Console.WriteLine("[2] Load: " + > span.TotalSeconds); > > > > //Execute > > d = DateTime.Now; > > engine.Execute("getContent(\"http://www.mininova.org\ > ")"); > > span = DateTime.Now - d; > > System.Console.WriteLine("[3] Execute: " + > > span.TotalSeconds); > > span = DateTime.Now - start; > > System.Console.WriteLine("Total: " + span.TotalSeconds); > > > > > > } > > } > > } > > > > > > On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland > > > > > wrote: > > > > We've actually had this issue reported once before a long time ago - > > it's a very low CodePlex ID - > > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 > > > > We haven't had a chance to investigate the end-to-end scenario. If > > someone could come up with a smaller simpler repro that'd be great. > > Otherwise we haven't forgotten about it we've just had more > > immediately pressing issues to work on :(. > > > > > > -----Original Message----- > > From: users-bounces at lists.ironpython.com > > > > [mailto:users-bounces at lists.ironpython.com > > ] On Behalf Of Michael > Foord > > Sent: Wednesday, February 20, 2008 5:20 AM > > To: Discussion of IronPython > > Subject: Re: [IronPython] Slow Performance of CPython libs? > > > > Birsch wrote: > > > Hi - We've been using IronPython successfully to allow > extensibility > > > of our application. > > > > > > Overall we are happy with the performance, with the exception of > > > BeautifulSoup which seems to run very slowly: x5 or more time to > > > execute compared to CPython. > > > > > > Most of the time seems to be spent during __init__() of BS, where > the > > > markup is parsed. > > > > > > We suspect this has to do with the fact that our CPython env is > > > executing .pyc files and can precompile its libs, while the > > IronPython > > > environment compiles each iteration. We couldn't find a way to > > > pre-compile the libs and then introduce them into the code, but > > in any > > > case this will result in a large management overhead since the > amount > > > of CPython libs we expose to our users contains 100's of modules. > > > > > > Any ideas on how to optimize? > > > > I think it is worth doing real profiling to find out where the time > is > > being spent during parsing. > > > > If it is spending most of the time in '__init__' then the time is > > probably not spent in importing - so compilation isn't relevant and > it > > is a runtime performance issue. (Importing is much slower with > > IronPython and at Resolver Systems we do use precompiled binaries - > but > > strangely enough it doesn't provide much of a performance gain.) > > > > Michael > > http://www.manning.com/foord > > > > > > > > Thanks, > > > -Birsch > > > > > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 runtime > DLLs > > > (this was done to overcome library incompatibilities and network > > > errors). However, the relevant slow .py code (mainly SGMLParser > and > > > BeautifulSoup) is the same. > > > > > > ------------------------------------------------------------------------ > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From birsch at gmail.com Sat Feb 23 13:53:35 2008 From: birsch at gmail.com (Birsch) Date: Sat, 23 Feb 2008 14:53:35 +0200 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <1e4778de0802221224i7ccc2386u99a04761d64515b4@mail.gmail.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> <1e4778de0802210830s60e4f13eue81dd421eca4677@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4EB6CCF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802211004k6a3fbdf4i79d8de7fd243c6c1@mail.gmail.com> <47BDC089.90106@houmus.org> <7AD436E4270DD54A94238001769C2227011CF4EB6D2B@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802220940t433773dek4fcd8f414232f6d6@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4EB7035@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802221224i7ccc2386u99a04761d64515b4@mail.gmail.com> Message-ID: <1e4778de0802230453j17785bc5x5fb3c1d668c521f9@mail.gmail.com> Update: I patched re.cs with a compile-check flag (same as Dino), and while it knocked off 25%, it still remained very slow in comparison to CPython (x5-x10). So I ran the profiler again on the patched code: Namespace Method name Time (sec.) Time with children (sec.) Hit count Source file IronPython.Runtime.Operations Ops.CallWithContext(ICallerContext context, object func, object arg0, object arg1) 5.7779 35.5915 75882 System.Text.RegularExpressions CompiledRegexRunner.Go() 5.3627 19.9116 13684621 IronPython.Runtime.Calls Method.Call(ICallerContext context, object arg0) 5.0284 36.0412 50886 IronPython.Runtime.Calls PythonFunction.CallInstance(ICallerContext context, object arg0, object arg1) 5.0055 36.0168 50886 IronPython.Runtime.Calls Function2.Call(ICallerContext context, object arg0, object arg1) 4.7494 35.7496 47485 IronPython.Runtime.Operations Ops.CallWithContext(ICallerContext context, object func, object arg0) 4.3452 35.3645 146642 System.Text.RegularExpressions RegexCharClass.CharInClassRecursive(char ch, string set, int start) 4.0303 6.0294 31498121 System.Text.RegularExpressions RegexCharClass.CharInClass(char ch, string set) 3.7132 9.7426 31498121 System.Text.RegularExpressions RegexRunner.CharInClass(char ch, string charClass) 3.1865 12.9291 31498114 IronPython.Runtime.Calls Method.Call(ICallerContext context, object arg0, object arg1) 3.1467 8.2760 15008 IronPython.Runtime.Calls PythonFunction.CallInstance(ICallerContext context, object arg0, object arg1, object arg2) 3.1440 8.2725 15008 System.Text.RegularExpressions RegexCharClass.CharInClassInternal(char ch, string set, int start, int mySetLength, int myCategoryLength) 1.9806 1.9991 31498121 System.Text.RegularExpressions RegexRunner.EnsureStorage() 1.6674 1.6674 37765633 System.Text.RegularExpressions RegexRunner.Scan(Regex regex, string text, int textbeg, int textend, int textstart, int prevlen, bool quick) 1.5465 22.9673 39137 IronPython.Runtime.Operations Ops.GetAttr(ICallerContext context, object o, SymbolId name) 1.5139 5.5342 546878 System.Text.RegularExpressions CompiledRegexRunner.FindFirstChar() 1.3493 1.4119 13689019 IronPython.Runtime.Types OldClass.TryLookupSlot(SymbolId name, out object ret) 1.2987 2.4052 350822 System.Globalization CompareInfo.IsPrefix(string source, string prefix, CompareOptions options) 0.3656 0.3669 3421 IronPython.Runtime SymbolId.op_Equality(SymbolId a, SymbolId b) 0.3635 0.3635 7974446 IronPython.Runtime CustomSymbolDict.TryGetValue(SymbolId key, out object value) 0.2286 1.3466 1165376 System String.InternalSubString(int startIndex, int length, bool fAlwaysCopy) 0.2253 0.3669 52536 IronPython.Runtime.Calls FunctionEnvironmentNDictionary.TryGetExtraValue(SymbolId key, out object value) 0.2228 0.4089 152594 IronPython.Runtime.Types OldInstance.TryGetAttr(ICallerContext context, SymbolId name, out object value) 0.2156 3.0540 396617 IronPython.Runtime.Calls Function3.Call(ICallerContext context, object arg0, object arg1, object arg2) 0.2109 5.3373 11221 System String.wstrcpy(char* dmem, char* smem, int charCount) 0.1831 0.1831 621212 System.Collections.Generic Dictionary.FindEntry(TKey key) 0.1460 0.3733 558255 IronPython.Runtime.Calls FunctionEnvironment32Dictionary.TryGetExtraValue(SymbolId key, out object value) 0.1457 0.2680 103477 IronPython.Runtime.Types DynamicType.TryGetSlot(ICallerContext context, SymbolId name, out object ret) 0.1367 0.3618 406706 IronPython.Runtime.Operations Ops.CallWithContext(ICallerContext context, object func, object[] args) 0.1326 1.7429 10267 sgmllib.finish_starttag$f318(FunctionEnvironment32Dictionary $env, object self, object tag, object attrs) 0.1213 5.0059 3787 If I'm reading this correctly, it now runs the compiled regex code, and the performance diff boils down to regex performance itself. Dan Shechter mentioned earlier an option of generating regex-pattern-specific runtime code. With almost an order of magnitude to knock off here - do you think that will do the trick? -Birsch On Fri, Feb 22, 2008 at 10:24 PM, Birsch wrote: > Great, you've got my vote :) > > Thanks a lot for your help. > > > On Fri, Feb 22, 2008 at 9:03 PM, Dino Viehland < > dinov at exchange.microsoft.com> wrote: > > > Oh, and I've gone ahead and created a bug for this one for 2.0: > > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=15289 > > > > > > > > *From:* users-bounces at lists.ironpython.com [mailto: > > users-bounces at lists.ironpython.com] *On Behalf Of *Birsch > > *Sent:* Friday, February 22, 2008 9:40 AM > > > > *To:* Discussion of IronPython > > *Subject:* Re: [IronPython] Slow Performance of CPython libs? > > > > > > > > Dino - do you want me to register a workitem? Also, if I wanted to patch > > v1.1.1, where should I start? > > > > On Thu, Feb 21, 2008 at 8:48 PM, Dino Viehland < > > dinov at exchange.microsoft.com> wrote: > > > > After Birsh's last comment that they're calling compile I was thinking > > we might be doing something really stupid. Turns out that we are. For our > > supposedly compiled regex's we're not passing the Compiled option. So > > they're all getting interpretted and of course that's going to suck big > > time. > > > > So the fix for this is probably to just pass RegexOptions.Compiled to > > the Regex object being contructed into RE_Pattern. Internally the Regex > > class will compile to dynamic methods (much better than compiling to an > > assembly because it'll be collectible). > > > > It's actually a little more complex than that because we create > > RE_Pattern objects for the non-compiled so we need to flow the option in, > > but it's still a simple fix. > > > > > > -----Original Message----- > > From: users-bounces at lists.ironpython.com [mailto: > > users-bounces at lists.ironpython.com] On Behalf Of Dan Shechter > > Sent: Thursday, February 21, 2008 10:19 AM > > To: Discussion of IronPython > > Subject: Re: [IronPython] Slow Performance of CPython libs? > > > > Just out of curiosity... > > I'm guessing that there are two levels of caching that could be used. > > One would be to hold a global dictionary of some sort of pattern -> > > Regex that will save the lengthy parsing of the re. > > > > The other would be to actually call Regex.CompileToAssembly to get a > > more efficient reperesentation (in runtime that is) of the re. > > > > Would you (the IP team) favor the former or the latter? > > > > Shechter. > > > > > > Birsch wrote: > > > I checked both sgmllib.py and BeautifulSoup.py - and it seems both are > > > reusing the same regexps (searched for re.compile). > > > > > > I think your suggestion is very relevant in this case. It makes sense > > to > > > replicate the "compile once use many" behavior that is commonly used > > > with regexp. > > > > > > -Birsch > > > > > > On Thu, Feb 21, 2008 at 7:30 PM, Dino Viehland > > > > > > wrote: > > > > > > Do you know if the same reg ex is being used repeatedly? If so > > > maybe we can cache & compile the regex instead of interpretting it > > > all the time. > > > > > > > > > > > > *From:* users-bounces at lists.ironpython.com > > > > > > [mailto:users-bounces at lists.ironpython.com > > > ] *On Behalf Of *Birsch > > > *Sent:* Thursday, February 21, 2008 8:30 AM > > > > > > *To:* Discussion of IronPython > > > *Subject:* Re: [IronPython] Slow Performance of CPython libs? > > > > > > > > > > > > I took on Cooper's advice and profiled with ANTS. Here are the top > > > methods: > > > > > > *Namespace* > > > > > > > > > > > > *Method name* > > > > > > > > > > > > *Time (sec.)* > > > > > > > > > > > > *Time with children (sec.)* > > > > > > > > > > > > *Hit count* > > > > > > > > > > > > *Source file* > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.Go() > > > > > > > > > > > > 37.0189 > > > > > > > > > > > > 94.4676 > > > > > > > > > > > > 13689612 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.Operator() > > > > > > > > > > > > 6.2411 > > > > > > > > > > > > 6.2411 > > > > > > > > > > > > 131146274 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.Advance(int i) > > > > > > > > > > > > 5.9264 > > > > > > > > > > > > 8.7202 > > > > > > > > > > > > 66000263 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.SetOperator(int op) > > > > > > > > > > > > 5.5750 > > > > > > > > > > > > 5.5750 > > > > > > > > > > > > 131146274 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.Backtrack() > > > > > > > > > > > > 5.5692 > > > > > > > > > > > > 9.4895 > > > > > > > > > > > > 37781343 > > > > > > > > > > > > IronPython.Runtime.Operations > > > > > > > > > > > > Ops.CallWithContext(ICallerContext context, object func, object > > > arg0, object arg1) > > > > > > > > > > > > 5.5572 > > > > > > > > > > > > 114.5245 > > > > > > > > > > > > 79754 > > > > > > > > > > > > IronPython.Runtime.Calls > > > > > > > > > > > > Method.Call(ICallerContext context, object arg0) > > > > > > > > > > > > 4.9052 > > > > > > > > > > > > 114.8251 > > > > > > > > > > > > 50886 > > > > > > > > > > > > IronPython.Runtime.Calls > > > > > > > > > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > > > object arg1) > > > > > > > > > > > > 4.8876 > > > > > > > > > > > > 114.8059 > > > > > > > > > > > > 50886 > > > > > > > > > > > > IronPython.Runtime.Calls > > > > > > > > > > > > Function2.Call(ICallerContext context, object arg0, object arg1) > > > > > > > > > > > > 4.6400 > > > > > > > > > > > > 114.5471 > > > > > > > > > > > > 47486 > > > > > > > > > > > > IronPython.Runtime.Operations > > > > > > > > > > > > Ops.CallWithContext(ICallerContext context, object func, object > > arg0) > > > > > > > > > > > > 4.2344 > > > > > > > > > > > > 114.1604 > > > > > > > > > > > > 146658 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexBoyerMoore.Scan(string text, int index, int beglimit, int > > endlimit) > > > > > > > > > > > > 3.6465 > > > > > > > > > > > > 3.6465 > > > > > > > > > > > > 13678131 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexCharClass.CharInClassRecursive(char ch, string set, int > > start) > > > > > > > > > > > > 3.6288 > > > > > > > > > > > > 5.7113 > > > > > > > > > > > > 31508162 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.Goto(int newpos) > > > > > > > > > > > > 3.2058 > > > > > > > > > > > > 5.1470 > > > > > > > > > > > > 27364668 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.Operand(int i) > > > > > > > > > > > > 3.1923 > > > > > > > > > > > > 3.1923 > > > > > > > > > > > > 73230687 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexRunner.EnsureStorage() > > > > > > > > > > > > 3.0803 > > > > > > > > > > > > 3.0803 > > > > > > > > > > > > 51474823 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexCharClass.CharInClass(char ch, string set) > > > > > > > > > > > > 3.0713 > > > > > > > > > > > > 8.7827 > > > > > > > > > > > > 31508162 > > > > > > > > > > > > IronPython.Runtime.Calls > > > > > > > > > > > > Method.Call(ICallerContext context, object arg0, object arg1) > > > > > > > > > > > > 2.9821 > > > > > > > > > > > > 7.8675 > > > > > > > > > > > > 15012 > > > > > > > > > > > > IronPython.Runtime.Calls > > > > > > > > > > > > PythonFunction.CallInstance(ICallerContext context, object arg0, > > > object arg1, object arg2) > > > > > > > > > > > > 2.9794 > > > > > > > > > > > > 7.8639 > > > > > > > > > > > > 15012 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.Forwardcharnext() > > > > > > > > > > > > 2.8852 > > > > > > > > > > > > 2.8852 > > > > > > > > > > > > 62865185 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.Forwardchars() > > > > > > > > > > > > 2.8279 > > > > > > > > > > > > 2.8279 > > > > > > > > > > > > 59436277 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexCharClass.CharInClassInternal(char ch, string set, int start, > > > int mySetLength, int myCategoryLength) > > > > > > > > > > > > 2.0632 > > > > > > > > > > > > 2.0826 > > > > > > > > > > > > 31508162 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexRunner.Scan(Regex regex, string text, int textbeg, int > > textend, > > > int textstart, int prevlen, bool quick) > > > > > > > > > > > > 1.8376 > > > > > > > > > > > > 101.7226 > > > > > > > > > > > > 43009 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.FindFirstChar() > > > > > > > > > > > > 1.6405 > > > > > > > > > > > > 5.3456 > > > > > > > > > > > > 13701755 > > > > > > > > > > > > IronPython.Runtime.Types > > > > > > > > > > > > OldClass.TryLookupSlot(SymbolId name, out object ret) > > > > > > > > > > > > 1.5573 > > > > > > > > > > > > 2.8124 > > > > > > > > > > > > 389516 > > > > > > > > > > > > IronPython.Runtime.Operations > > > > > > > > > > > > Ops.GetAttr(ICallerContext context, object o, SymbolId name) > > > > > > > > > > > > 1.5365 > > > > > > > > > > > > 5.3456 > > > > > > > > > > > > 558524 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.Textpos() > > > > > > > > > > > > 1.4020 > > > > > > > > > > > > 1.4020 > > > > > > > > > > > > 32648926 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.Advance() > > > > > > > > > > > > 1.1916 > > > > > > > > > > > > 2.9526 > > > > > > > > > > > > 13703950 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.Textto(int newpos) > > > > > > > > > > > > 1.1218 > > > > > > > > > > > > 1.1218 > > > > > > > > > > > > 24120890 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.TrackPeek() > > > > > > > > > > > > 1.0579 > > > > > > > > > > > > 1.0579 > > > > > > > > > > > > 24120894 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > Regex.Run(bool quick, int prevlen, string input, int beginning, > > int > > > length, int startat) > > > > > > > > > > > > 0.7280 > > > > > > > > > > > > 102.4644 > > > > > > > > > > > > 43009 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.TrackPush(int I1) > > > > > > > > > > > > 0.6834 > > > > > > > > > > > > 0.6834 > > > > > > > > > > > > 13745149 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.StackPush(int I1) > > > > > > > > > > > > 0.6542 > > > > > > > > > > > > 0.6542 > > > > > > > > > > > > 13703955 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.TrackPop() > > > > > > > > > > > > 0.6068 > > > > > > > > > > > > 0.6068 > > > > > > > > > > > > 13663035 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.TrackPush() > > > > > > > > > > > > 0.6049 > > > > > > > > > > > > 0.6049 > > > > > > > > > > > > 13708230 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.StackPop() > > > > > > > > > > > > 0.5836 > > > > > > > > > > > > 0.5836 > > > > > > > > > > > > 13703956 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.Bump() > > > > > > > > > > > > 0.4987 > > > > > > > > > > > > 0.4987 > > > > > > > > > > > > 10472790 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.TrackPush(int I1, int I2) > > > > > > > > > > > > 0.4864 > > > > > > > > > > > > 0.4864 > > > > > > > > > > > > 10472790 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.TrackPeek(int i) > > > > > > > > > > > > 0.4663 > > > > > > > > > > > > 0.4663 > > > > > > > > > > > > 10457859 > > > > > > > > > > > > System.Text.RegularExpressions > > > > > > > > > > > > RegexInterpreter.TrackPop(int framesize) > > > > > > > > > > > > 0.4396 > > > > > > > > > > > > 0.4396 > > > > > > > > > > > > 10457859 > > > > > > > > > > > > > > > Moving up the stack of regex.Go(), most calls originate from > > > sgmllib's parse_starttag. > > > > > > HTH, > > > -Birsch > > > > > > On Thu, Feb 21, 2008 at 2:35 PM, Birsch > > > wrote: > > > > > > Thanks Michael and Dino. > > > > > > I'll prof and send update. Got a good profiler recommendation for > > .Net? > > > Meanwhile I noticed the sample site below causes BeautifulSoup to > > > generate quite a few [python] exceptions during __init__. Does > > > IronPython handle exceptions significantly slower than CPtyhon? > > > > > > Repro code is simple (just build a BeautifulSoup obj with > > mininova's > > > home page). > > > Here are the .py and .cs I used to time the diffs: > > > > > > *bstest.py:* > > > #Bypass CPython default socket implementation with IPCE/FePy > > > import imp, os, sys > > > sys.modules['socket'] = module = imp.new_module('socket') > > > execfile('socket.py', module.__dict__) > > > > > > from BeautifulSoup import BeautifulSoup > > > from urllib import urlopen > > > import datetime > > > > > > def getContent(url): > > > #Download html data > > > startTime = datetime.datetime.now() > > > print "Getting url", url > > > html = urlopen(url).read() > > > print "Time taken:", datetime.datetime.now() - startTime > > > > > > #Make soup > > > startTime = datetime.datetime.now() > > > print "Making soup..." > > > soup = BeautifulSoup(markup=html) > > > print "Time taken:", datetime.datetime.now() - startTime > > > > > > if __name__ == "__main__": > > > print getContent("www.mininova.org ") > > > > > > > > > *C#:* > > > using System; > > > using System.Collections.Generic; > > > using System.Text; > > > using IronPython.Hosting; > > > > > > namespace IronPythonBeautifulSoupTest > > > { > > > public class Program > > > { > > > public static void Main(string[] args) > > > { > > > //Init > > > System.Console.WriteLine("Starting..."); > > > DateTime start = DateTime.Now; > > > PythonEngine engine = new PythonEngine(); > > > > > > //Add paths: > > > //BeautifulSoup.py, socket.py, bstest.py located on > > exe dir > > > engine.AddToPath(@"."); > > > //CPython Lib (replace with your own) > > > engine.AddToPath(@"D:\Dev\Python\Lib"); > > > > > > //Import and load > > > TimeSpan span = DateTime.Now - start; > > > System.Console.WriteLine("[1] Import: " + > > > span.TotalSeconds); > > > DateTime d = DateTime.Now; > > > engine.ExecuteFile(@"bstest.py"); > > > span = DateTime.Now - d; > > > System.Console.WriteLine("[2] Load: " + > > span.TotalSeconds); > > > > > > //Execute > > > d = DateTime.Now; > > > engine.Execute("getContent(\"http://www.mininova.org\ > > ")"); > > > span = DateTime.Now - d; > > > System.Console.WriteLine("[3] Execute: " + > > > span.TotalSeconds); > > > span = DateTime.Now - start; > > > System.Console.WriteLine("Total: " + span.TotalSeconds > > ); > > > > > > > > > } > > > } > > > } > > > > > > > > > On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland > > > > >> > > > wrote: > > > > > > We've actually had this issue reported once before a long time ago > > - > > > it's a very low CodePlex ID - > > > > > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 > > > > > > We haven't had a chance to investigate the end-to-end scenario. > > If > > > someone could come up with a smaller simpler repro that'd be > > great. > > > Otherwise we haven't forgotten about it we've just had more > > > immediately pressing issues to work on :(. > > > > > > > > > -----Original Message----- > > > From: users-bounces at lists.ironpython.com > > > > > > [mailto:users-bounces at lists.ironpython.com > > > ] On Behalf Of Michael > > Foord > > > Sent: Wednesday, February 20, 2008 5:20 AM > > > To: Discussion of IronPython > > > Subject: Re: [IronPython] Slow Performance of CPython libs? > > > > > > Birsch wrote: > > > > Hi - We've been using IronPython successfully to allow > > extensibility > > > > of our application. > > > > > > > > Overall we are happy with the performance, with the exception > > of > > > > BeautifulSoup which seems to run very slowly: x5 or more time > > to > > > > execute compared to CPython. > > > > > > > > Most of the time seems to be spent during __init__() of BS, > > where the > > > > markup is parsed. > > > > > > > > We suspect this has to do with the fact that our CPython env is > > > > executing .pyc files and can precompile its libs, while the > > > IronPython > > > > environment compiles each iteration. We couldn't find a way to > > > > pre-compile the libs and then introduce them into the code, but > > > in any > > > > case this will result in a large management overhead since the > > amount > > > > of CPython libs we expose to our users contains 100's of > > modules. > > > > > > > > Any ideas on how to optimize? > > > > > > I think it is worth doing real profiling to find out where the > > time is > > > being spent during parsing. > > > > > > If it is spending most of the time in '__init__' then the time is > > > probably not spent in importing - so compilation isn't relevant > > and it > > > is a runtime performance issue. (Importing is much slower with > > > IronPython and at Resolver Systems we do use precompiled binaries > > - but > > > strangely enough it doesn't provide much of a performance gain.) > > > > > > Michael > > > http://www.manning.com/foord > > > > > > > > > > > Thanks, > > > > -Birsch > > > > > > > > Note: we're using FePy/IPCE libs with regular IP v1.1.1 runtime > > DLLs > > > > (this was done to overcome library incompatibilities and > > network > > > > errors). However, the relevant slow .py code (mainly SGMLParser > > and > > > > BeautifulSoup) is the same. > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > _______________________________________________ > > > > Users mailing list > > > > Users at lists.ironpython.com > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dans at houmus.org Sat Feb 23 17:25:25 2008 From: dans at houmus.org (Dan Shechter) Date: Sat, 23 Feb 2008 11:25:25 -0500 Subject: [IronPython] Slow Performance of CPython libs? In-Reply-To: <1e4778de0802230453j17785bc5x5fb3c1d668c521f9@mail.gmail.com> References: <1e4778de0802200358x65796d13s57a23efe65bb1777@mail.gmail.com> <1e4778de0802210435n1b26d51tf2944af5a010c142@mail.gmail.com> <1e4778de0802210830s60e4f13eue81dd421eca4677@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4EB6CCF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802211004k6a3fbdf4i79d8de7fd243c6c1@mail.gmail.com> <47BDC089.90106@houmus.org> <7AD436E4270DD54A94238001769C2227011CF4EB6D2B@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802220940t433773dek4fcd8f414232f6d6@mail.gmail.com> <7AD436E4270DD54A94238001769C2227011CF4EB7035@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <1e4778de0802221224i7ccc2386u99a04761d64515b4@mail.gmail.com> <1e4778de0802230453j17785bc5x5fb3c1d668c521f9@mail.gmail.com> Message-ID: <47C048F5.5050804@houmus.org> Well it does look interesting, but I think there is something flawed with my own suggestion as a general rule. As someone mentioned here, the CompileToAssembly() does create a new assembly, which gets loaded it into the AppDomain (eventually) and it doesn't get reclaimed for eternity (forgive my melodrama). So I would definitely not "suggest" it as a general solution for all Regex woes in the world. I would try, just for the fun of it to patch IP to use CompileToAssembly() just to see how much time in reality does it knock off the profiling / general runtime. Also note that your profiler might be causing you faux-visages of performance. Have you tried to just time the two different versions without profiling? perhaps performance is already "Good Enough"? Birsch wrote: > Update: > > I patched re.cs with a compile-check flag (same as Dino), and while it > knocked off 25%, it still remained very slow in comparison to CPython > (x5-x10). > So I ran the profiler again on the patched code: > > Namespace Method name Time (sec.) Time with children (sec.) Hit > count Source file > IronPython.Runtime.Operations Ops.CallWithContext(ICallerContext > context, object func, object arg0, object arg1) 5.7779 35.5915 75882 > System.Text.RegularExpressions CompiledRegexRunner.Go() 5.3627 > 19.9116 13684621 > IronPython.Runtime.Calls Method.Call(ICallerContext context, object > arg0) 5.0284 36.0412 50886 > IronPython.Runtime.Calls PythonFunction.CallInstance(ICallerContext > context, object arg0, object arg1) 5.0055 36.0168 50886 > IronPython.Runtime.Calls Function2.Call(ICallerContext context, object > arg0, object arg1) 4.7494 35.7496 47485 > IronPython.Runtime.Operations Ops.CallWithContext(ICallerContext > context, object func, object arg0) 4.3452 35.3645 146642 > System.Text.RegularExpressions RegexCharClass.CharInClassRecursive(char > ch, string set, int start) 4.0303 6.0294 31498121 > System.Text.RegularExpressions RegexCharClass.CharInClass(char ch, > string set) 3.7132 9.7426 31498121 > System.Text.RegularExpressions RegexRunner.CharInClass(char ch, string > charClass) 3.1865 12.9291 31498114 > IronPython.Runtime.Calls Method.Call(ICallerContext context, object > arg0, object arg1) 3.1467 8.2760 15008 > IronPython.Runtime.Calls PythonFunction.CallInstance(ICallerContext > context, object arg0, object arg1, object arg2) 3.1440 8.2725 15008 > System.Text.RegularExpressions RegexCharClass.CharInClassInternal(char > ch, string set, int start, int mySetLength, int myCategoryLength) > 1.9806 1.9991 31498121 > System.Text.RegularExpressions RegexRunner.EnsureStorage() 1.6674 > 1.6674 37765633 > System.Text.RegularExpressions RegexRunner.Scan(Regex regex, string > text, int textbeg, int textend, int textstart, int prevlen, bool > quick) 1.5465 22.9673 39137 > IronPython.Runtime.Operations Ops.GetAttr(ICallerContext context, > object o, SymbolId name) 1.5139 5.5342 546878 > System.Text.RegularExpressions CompiledRegexRunner.FindFirstChar() > 1.3493 1.4119 13689019 > IronPython.Runtime.Types OldClass.TryLookupSlot(SymbolId name, out > object ret) 1.2987 2.4052 350822 > System.Globalization CompareInfo.IsPrefix(string source, string prefix, > CompareOptions options) 0.3656 0.3669 3421 > IronPython.Runtime SymbolId.op_Equality(SymbolId a, SymbolId b) > 0.3635 0.3635 7974446 > IronPython.Runtime CustomSymbolDict.TryGetValue(SymbolId key, out > object value) 0.2286 1.3466 1165376 > System String.InternalSubString(int startIndex, int length, bool > fAlwaysCopy) 0.2253 0.3669 52536 > IronPython.Runtime.Calls > FunctionEnvironmentNDictionary.TryGetExtraValue(SymbolId key, out object > value) 0.2228 0.4089 152594 > IronPython.Runtime.Types OldInstance.TryGetAttr(ICallerContext context, > SymbolId name, out object value) 0.2156 3.0540 396617 > IronPython.Runtime.Calls Function3.Call(ICallerContext context, object > arg0, object arg1, object arg2) 0.2109 5.3373 11221 > System String.wstrcpy(char* dmem, char* smem, int charCount) 0.1831 > 0.1831 621212 > System.Collections.Generic Dictionary.FindEntry(TKey > key) 0.1460 0.3733 558255 > IronPython.Runtime.Calls > FunctionEnvironment32Dictionary.TryGetExtraValue(SymbolId key, out > object value) 0.1457 0.2680 103477 > IronPython.Runtime.Types DynamicType.TryGetSlot(ICallerContext context, > SymbolId name, out object ret) 0.1367 0.3618 406706 > IronPython.Runtime.Operations Ops.CallWithContext(ICallerContext > context, object func, object[] args) 0.1326 1.7429 10267 > > sgmllib.finish_starttag$f318(FunctionEnvironment32Dictionary $env, > object self, object tag, object attrs) 0.1213 5.0059 3787 > > > If I'm reading this correctly, it now runs the compiled regex code, and > the performance diff boils down to regex performance itself. > > Dan Shechter mentioned earlier an option of generating > regex-pattern-specific runtime code. With almost an order of magnitude > to knock off here - do you think that will do the trick? > > -Birsch > > On Fri, Feb 22, 2008 at 10:24 PM, Birsch > wrote: > > Great, you've got my vote :) > > Thanks a lot for your help. > > > On Fri, Feb 22, 2008 at 9:03 PM, Dino Viehland > > > wrote: > > Oh, and I've gone ahead and created a bug for this one for 2.0: > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=15289 > > > > *From:* users-bounces at lists.ironpython.com > > [mailto:users-bounces at lists.ironpython.com > ] *On Behalf Of *Birsch > *Sent:* Friday, February 22, 2008 9:40 AM > > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] Slow Performance of CPython libs? > > > > Dino - do you want me to register a workitem? Also, if I wanted > to patch v1.1.1, where should I start? > > On Thu, Feb 21, 2008 at 8:48 PM, Dino Viehland > > wrote: > > After Birsh's last comment that they're calling compile I was > thinking we might be doing something really stupid. Turns out > that we are. For our supposedly compiled regex's we're not > passing the Compiled option. So they're all getting > interpretted and of course that's going to suck big time. > > So the fix for this is probably to just pass > RegexOptions.Compiled to the Regex object being contructed into > RE_Pattern. Internally the Regex class will compile to dynamic > methods (much better than compiling to an assembly because it'll > be collectible). > > It's actually a little more complex than that because we create > RE_Pattern objects for the non-compiled so we need to flow the > option in, but it's still a simple fix. > > > -----Original Message----- > From: users-bounces at lists.ironpython.com > > [mailto:users-bounces at lists.ironpython.com > ] On Behalf Of Dan > Shechter > Sent: Thursday, February 21, 2008 10:19 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Slow Performance of CPython libs? > > Just out of curiosity... > I'm guessing that there are two levels of caching that could be > used. > One would be to hold a global dictionary of some sort of pattern -> > Regex that will save the lengthy parsing of the re. > > The other would be to actually call Regex.CompileToAssembly to get a > more efficient reperesentation (in runtime that is) of the re. > > Would you (the IP team) favor the former or the latter? > > Shechter. > > > Birsch wrote: > > I checked both sgmllib.py and BeautifulSoup.py - and it seems > both are > > reusing the same regexps (searched for re.compile). > > > > I think your suggestion is very relevant in this case. It > makes sense to > > replicate the "compile once use many" behavior that is > commonly used > > with regexp. > > > > -Birsch > > > > On Thu, Feb 21, 2008 at 7:30 PM, Dino Viehland > > > >> wrote: > > > > Do you know if the same reg ex is being used repeatedly? > If so > > maybe we can cache & compile the regex instead of > interpretting it > > all the time. > > > > > > > > *From:* users-bounces at lists.ironpython.com > > > > > > [mailto:users-bounces at lists.ironpython.com > > > >] *On Behalf Of *Birsch > > *Sent:* Thursday, February 21, 2008 8:30 AM > > > > *To:* Discussion of IronPython > > *Subject:* Re: [IronPython] Slow Performance of CPython libs? > > > > > > > > I took on Cooper's advice and profiled with ANTS. Here > are the top > > methods: > > > > *Namespace* > > > > > > > > *Method name* > > > > > > > > *Time (sec.)* > > > > > > > > *Time with children (sec.)* > > > > > > > > *Hit count* > > > > > > > > *Source file* > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Go() > > > > > > > > 37.0189 > > > > > > > > 94.4676 > > > > > > > > 13689612 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Operator() > > > > > > > > 6.2411 > > > > > > > > 6.2411 > > > > > > > > 131146274 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Advance(int i) > > > > > > > > 5.9264 > > > > > > > > 8.7202 > > > > > > > > 66000263 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.SetOperator(int op) > > > > > > > > 5.5750 > > > > > > > > 5.5750 > > > > > > > > 131146274 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Backtrack() > > > > > > > > 5.5692 > > > > > > > > 9.4895 > > > > > > > > 37781343 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.CallWithContext(ICallerContext context, object func, > object > > arg0, object arg1) > > > > > > > > 5.5572 > > > > > > > > 114.5245 > > > > > > > > 79754 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Method.Call(ICallerContext context, object arg0) > > > > > > > > 4.9052 > > > > > > > > 114.8251 > > > > > > > > 50886 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > PythonFunction.CallInstance(ICallerContext context, > object arg0, > > object arg1) > > > > > > > > 4.8876 > > > > > > > > 114.8059 > > > > > > > > 50886 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Function2.Call(ICallerContext context, object arg0, > object arg1) > > > > > > > > 4.6400 > > > > > > > > 114.5471 > > > > > > > > 47486 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.CallWithContext(ICallerContext context, object func, > object arg0) > > > > > > > > 4.2344 > > > > > > > > 114.1604 > > > > > > > > 146658 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexBoyerMoore.Scan(string text, int index, int > beglimit, int endlimit) > > > > > > > > 3.6465 > > > > > > > > 3.6465 > > > > > > > > 13678131 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClassRecursive(char ch, string set, > int start) > > > > > > > > 3.6288 > > > > > > > > 5.7113 > > > > > > > > 31508162 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Goto(int newpos) > > > > > > > > 3.2058 > > > > > > > > 5.1470 > > > > > > > > 27364668 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Operand(int i) > > > > > > > > 3.1923 > > > > > > > > 3.1923 > > > > > > > > 73230687 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexRunner.EnsureStorage() > > > > > > > > 3.0803 > > > > > > > > 3.0803 > > > > > > > > 51474823 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClass(char ch, string set) > > > > > > > > 3.0713 > > > > > > > > 8.7827 > > > > > > > > 31508162 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > Method.Call(ICallerContext context, object arg0, object arg1) > > > > > > > > 2.9821 > > > > > > > > 7.8675 > > > > > > > > 15012 > > > > > > > > IronPython.Runtime.Calls > > > > > > > > PythonFunction.CallInstance(ICallerContext context, > object arg0, > > object arg1, object arg2) > > > > > > > > 2.9794 > > > > > > > > 7.8639 > > > > > > > > 15012 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Forwardcharnext() > > > > > > > > 2.8852 > > > > > > > > 2.8852 > > > > > > > > 62865185 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Forwardchars() > > > > > > > > 2.8279 > > > > > > > > 2.8279 > > > > > > > > 59436277 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexCharClass.CharInClassInternal(char ch, string set, > int start, > > int mySetLength, int myCategoryLength) > > > > > > > > 2.0632 > > > > > > > > 2.0826 > > > > > > > > 31508162 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexRunner.Scan(Regex regex, string text, int textbeg, > int textend, > > int textstart, int prevlen, bool quick) > > > > > > > > 1.8376 > > > > > > > > 101.7226 > > > > > > > > 43009 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.FindFirstChar() > > > > > > > > 1.6405 > > > > > > > > 5.3456 > > > > > > > > 13701755 > > > > > > > > IronPython.Runtime.Types > > > > > > > > OldClass.TryLookupSlot(SymbolId name, out object ret) > > > > > > > > 1.5573 > > > > > > > > 2.8124 > > > > > > > > 389516 > > > > > > > > IronPython.Runtime.Operations > > > > > > > > Ops.GetAttr(ICallerContext context, object o, SymbolId name) > > > > > > > > 1.5365 > > > > > > > > 5.3456 > > > > > > > > 558524 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Textpos() > > > > > > > > 1.4020 > > > > > > > > 1.4020 > > > > > > > > 32648926 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Advance() > > > > > > > > 1.1916 > > > > > > > > 2.9526 > > > > > > > > 13703950 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Textto(int newpos) > > > > > > > > 1.1218 > > > > > > > > 1.1218 > > > > > > > > 24120890 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPeek() > > > > > > > > 1.0579 > > > > > > > > 1.0579 > > > > > > > > 24120894 > > > > > > > > System.Text.RegularExpressions > > > > > > > > Regex.Run(bool quick, int prevlen, string input, int > beginning, int > > length, int startat) > > > > > > > > 0.7280 > > > > > > > > 102.4644 > > > > > > > > 43009 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush(int I1) > > > > > > > > 0.6834 > > > > > > > > 0.6834 > > > > > > > > 13745149 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.StackPush(int I1) > > > > > > > > 0.6542 > > > > > > > > 0.6542 > > > > > > > > 13703955 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPop() > > > > > > > > 0.6068 > > > > > > > > 0.6068 > > > > > > > > 13663035 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush() > > > > > > > > 0.6049 > > > > > > > > 0.6049 > > > > > > > > 13708230 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.StackPop() > > > > > > > > 0.5836 > > > > > > > > 0.5836 > > > > > > > > 13703956 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.Bump() > > > > > > > > 0.4987 > > > > > > > > 0.4987 > > > > > > > > 10472790 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPush(int I1, int I2) > > > > > > > > 0.4864 > > > > > > > > 0.4864 > > > > > > > > 10472790 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPeek(int i) > > > > > > > > 0.4663 > > > > > > > > 0.4663 > > > > > > > > 10457859 > > > > > > > > System.Text.RegularExpressions > > > > > > > > RegexInterpreter.TrackPop(int framesize) > > > > > > > > 0.4396 > > > > > > > > 0.4396 > > > > > > > > 10457859 > > > > > > > > > > Moving up the stack of regex.Go(), most calls originate from > > sgmllib's parse_starttag. > > > > HTH, > > -Birsch > > > > On Thu, Feb 21, 2008 at 2:35 PM, Birsch > > >> wrote: > > > > Thanks Michael and Dino. > > > > I'll prof and send update. Got a good profiler > recommendation for .Net? > > Meanwhile I noticed the sample site below causes > BeautifulSoup to > > generate quite a few [python] exceptions during __init__. > Does > > IronPython handle exceptions significantly slower than > CPtyhon? > > > > Repro code is simple (just build a BeautifulSoup obj with > mininova's > > home page). > > Here are the .py and .cs I used to time the diffs: > > > > *bstest.py:* > > #Bypass CPython default socket implementation with IPCE/FePy > > import imp, os, sys > > sys.modules['socket'] = module = imp.new_module('socket') > > execfile('socket.py', module.__dict__) > > > > from BeautifulSoup import BeautifulSoup > > from urllib import urlopen > > import datetime > > > > def getContent(url): > > #Download html data > > startTime = datetime.datetime.now() > > print "Getting url", url > > html = urlopen(url).read() > > print "Time taken:", datetime.datetime.now() - startTime > > > > #Make soup > > startTime = datetime.datetime.now() > > print "Making soup..." > > soup = BeautifulSoup(markup=html) > > print "Time taken:", datetime.datetime.now() - startTime > > > > if __name__ == "__main__": > > print getContent("www.mininova.org > ") > > > > > > *C#:* > > using System; > > using System.Collections.Generic; > > using System.Text; > > using IronPython.Hosting; > > > > namespace IronPythonBeautifulSoupTest > > { > > public class Program > > { > > public static void Main(string[] args) > > { > > //Init > > System.Console.WriteLine("Starting..."); > > DateTime start = DateTime.Now; > > PythonEngine engine = new PythonEngine(); > > > > //Add paths: > > //BeautifulSoup.py, socket.py, bstest.py > located on exe dir > > engine.AddToPath(@"."); > > //CPython Lib (replace with your own) > > engine.AddToPath(@"D:\Dev\Python\Lib"); > > > > //Import and load > > TimeSpan span = DateTime.Now - start; > > System.Console.WriteLine("[1] Import: " + > > span.TotalSeconds); > > DateTime d = DateTime.Now; > > engine.ExecuteFile(@"bstest.py"); > > span = DateTime.Now - d; > > System.Console.WriteLine("[2] Load: " + > span.TotalSeconds); > > > > //Execute > > d = DateTime.Now; > > > engine.Execute("getContent(\"http://www.mininova.org\ > ")"); > > span = DateTime.Now - d; > > System.Console.WriteLine("[3] Execute: " + > > span.TotalSeconds); > > span = DateTime.Now - start; > > System.Console.WriteLine("Total: " + > span.TotalSeconds); > > > > > > } > > } > > } > > > > > > On Wed, Feb 20, 2008 at 6:57 PM, Dino Viehland > > > >> > > wrote: > > > > We've actually had this issue reported once before a long > time ago - > > it's a very low CodePlex ID - > > > http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=651 > > > > We haven't had a chance to investigate the end-to-end > scenario. If > > someone could come up with a smaller simpler repro that'd > be great. > > Otherwise we haven't forgotten about it we've just had more > > immediately pressing issues to work on :(. > > > > > > -----Original Message----- > > From: users-bounces at lists.ironpython.com > > > > > > [mailto:users-bounces at lists.ironpython.com > > > >] On Behalf Of > Michael Foord > > Sent: Wednesday, February 20, 2008 5:20 AM > > To: Discussion of IronPython > > Subject: Re: [IronPython] Slow Performance of CPython libs? > > > > Birsch wrote: > > > Hi - We've been using IronPython successfully to allow > extensibility > > > of our application. > > > > > > Overall we are happy with the performance, with the > exception of > > > BeautifulSoup which seems to run very slowly: x5 or > more time to > > > execute compared to CPython. > > > > > > Most of the time seems to be spent during __init__() > of BS, where the > > > markup is parsed. > > > > > > We suspect this has to do with the fact that our > CPython env is > > > executing .pyc files and can precompile its libs, > while the > > IronPython > > > environment compiles each iteration. We couldn't find > a way to > > > pre-compile the libs and then introduce them into the > code, but > > in any > > > case this will result in a large management overhead > since the amount > > > of CPython libs we expose to our users contains 100's > of modules. > > > > > > Any ideas on how to optimize? > > > > I think it is worth doing real profiling to find out > where the time is > > being spent during parsing. > > > > If it is spending most of the time in '__init__' then the > time is > > probably not spent in importing - so compilation isn't > relevant and it > > is a runtime performance issue. (Importing is much slower > with > > IronPython and at Resolver Systems we do use precompiled > binaries - but > > strangely enough it doesn't provide much of a performance > gain.) > > > > Michael > > http://www.manning.com/foord > > > > > > > > Thanks, > > > -Birsch > > > > > > Note: we're using FePy/IPCE libs with regular IP > v1.1.1 runtime DLLs > > > (this was done to overcome library incompatibilities > and network > > > errors). However, the relevant slow .py code (mainly > SGMLParser and > > > BeautifulSoup) is the same. > > > > > > ------------------------------------------------------------------------ > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From Kyle.Howland-Rose at aar.com.au Sun Feb 24 23:22:27 2008 From: Kyle.Howland-Rose at aar.com.au (Howland-Rose, Kyle) Date: Mon, 25 Feb 2008 09:22:27 +1100 Subject: [IronPython] Returning inherited classes to .NET Message-ID: <204557C1883DCD40B4F8039D8E3C3B0827E98F@SYDEXCVS0.aar.com.au> Awesome, thanks Curt. Do you have any idea as to whether this is a bug or a feature? ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Saturday, 23 February 2008 1:33 AM To: Discussion of IronPython Subject: Re: [IronPython] FW: FW: FW: returning inherited classes to .NET I built a test executable and was able to reproduce this. And when I changed clr.AddReferenceToFile("WebControlLibrary.dll") to clr.AddReference("WebControlLibrary") it worked as expected. On Fri, Feb 22, 2008 at 6:02 AM, Curt Hagenlocher wrote: Ah, no. I was thinking that you would modify your VB code to launch it as a console app (for instance) rather than from inside of ASP.NET -- and see if you still get the same error. On Thu, Feb 21, 2008 at 10:07 PM, Howland-Rose, Kyle < Kyle.Howland-Rose at aar.com.au> wrote: Thanks for your help so late Curt (not that I need a quick answer at all). I am sure I am missing something big-time here and "talking" as cross-purposes, but, to my mind the reason I don't have a problem when running from the command line is because all I am doing is running the ipy.exe on the file which loads some assemblies, creates a class definition and a function definition and then terminates without even instantiating the class. Is this what you mean by "running it directly"? Thanks again, Kyle ________________________________ From: users-bounces at lists.ironpython.com [mailto: users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Friday, 22 February 2008 4:55 PM To: Discussion of IronPython Subject: Re: [IronPython] FW: FW: returning inherited classes to .NET If you're only getting the error under ASP.NET , then it's highly likely that you're loading multiple copies of the same assembly, which is why the CLR can't cast your Python class back to the VB base -- it literally considers them to be two different classes. This may be related to the way ASP.NET makes shadow copies of your files, but there could be other reasons as well (none of which, unfortunately, come to mind right now). Using an interface instead of a base class would give you the same results. On Thu, Feb 21, 2008 at 9:44 PM, Howland-Rose, Kyle < Kyle.Howland-Rose at aar.com.au> wrote: It runs fine from the command line but then it does not do much ... yet. For the moment I am simplifying it by removing IP :( I wanted to so some moderately heavy reflection which to my thinking should be easier from IP but I will use VB for now. I assume I *should* be able to return a derived python class to VB? Alternatively I could implement an interface. How can IP implement a .NET interface? (All pointers to pre-existing doco warmly received :) Thanks Kyle ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Friday, 22 February 2008 4:29 PM To: Discussion of IronPython Subject: Re: [IronPython] FW: returning inherited classes to .NET My apologies; I wasn't reading the code correctly. That's probably a sign that I should be going to bed. :) Have you tried simplifying your version just a little bit by running it directly rather than through ASP.NET ? On Thu, Feb 21, 2008 at 8:43 PM, Howland-Rose, Kyle wrote: Hi Curt, Thanks for replying. When I view the link I see the following: The .NET code creates the "Test" class and then runs the python code which imports the "Test" class a subclasses it to create python class "X". Class "X" is then called and cast to type "Test" and assigned to the value obj. Is this what you are looking at? My code is pretty much identical. The VB looks like: Public MustInherit Class ChildControl Public Function Control() As WebControl Return Nothing End Function Public Function GetValue() As String Return Nothing End Function Public Function SetValue(ByVal value As Object) As String Return Nothing End Function End Class Class IPReflection Private Shared Instance As IPReflection = Nothing Private PyEngine As PythonEngine Private PyModule As EngineModule Public Shared Function Inst() As IPReflection If Instance Is Nothing Then Instance = New IPReflection End If Return Instance End Function Private Sub New() Dim path As String = HttpContext.Current.Request.MapPath(".") PyEngine = New PythonEngine PyEngine.AddToPath(path) PyModule = PyEngine.CreateModule PyEngine.DefaultModule = PyModule PyEngine.ExecuteFile(HttpContext.Current.Request.MapPath("CustomControls .py")) End Sub Public Function GetChildControl() As ChildControl Return CType(Operations.Ops.Call(PyModule.Globals("GetControl")), ChildControl) End Function End Class And the python looks like: import clr import sys clr.AddReference('System') import System sys.path.append(sys.path[0] + "/bin") clr.AddReferenceToFile("WebControlLibrary.dll") clr.AddReference('System.Web') from System.Web.UI.WebControls import Label from WebControlLibrary import ChildControl class LabelChildControl(ChildControl): def __init__(self): self.control = Label() def Control(self): return self.control def GetControl(): return LabelChildControl() Thanks again, Kyle ________________________________ From: users-bounces at lists.ironpython.com [mailto: users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Friday, 22 February 2008 3:08 PM To: Discussion of IronPython Subject: Re: [IronPython] returning inherited classes to .NET The page in question doesn't seem to show what you describe -- deriving a Python class from a C# class. Maybe you could show us your sample code? On Thu, Feb 21, 2008 at 7:39 PM, Howland-Rose, Kyle wrote: Hi all, I am following http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET < http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET> but using VB. In VB I declare a class and derive a python 1.1 class from it but when I return it I get the exception: "Unable to cast object of type 'IronPython.NewTypes.WebControlLibrary.ChildControl_1' to type 'WebControlLibrary.ChildControl'." The page referenced above just seems to cast the python class instance to the C# class instance but this does not work for me in VB. Any help would be appreciated :) Thanks, Kyle ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************* -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: ATT599039.txt URL: From curt at hagenlocher.org Mon Feb 25 00:30:53 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Sun, 24 Feb 2008 15:30:53 -0800 Subject: [IronPython] Returning inherited classes to .NET In-Reply-To: <204557C1883DCD40B4F8039D8E3C3B0827E98F@SYDEXCVS0.aar.com.au> References: <204557C1883DCD40B4F8039D8E3C3B0827E98F@SYDEXCVS0.aar.com.au> Message-ID: It's a feature. clr.AddReferenceToFile ends up calling Assembly.LoadFileunder the covers, which lets you load multiple versions of the same assembly. If this isn't the behavior you want, you should use a differently variant of AddReference (such as clr.AddReference). Each variant has its uses; this one's don't correspond well with your intentions. On Sun, Feb 24, 2008 at 2:22 PM, Howland-Rose, Kyle < Kyle.Howland-Rose at aar.com.au> wrote: > Awesome, thanks Curt. > > Do you have any idea as to whether this is a bug or a feature? > > ------------------------------ > *From:* users-bounces at lists.ironpython.com [mailto: > users-bounces at lists.ironpython.com] *On Behalf Of *Curt Hagenlocher > *Sent:* Saturday, 23 February 2008 1:33 AM > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] FW: FW: FW: returning inherited classes to > .NET > > I built a test executable and was able to reproduce this. And when I > changed > clr.AddReferenceToFile("WebControlLibrary.dll") > to > clr.AddReference("WebControlLibrary") > it worked as expected. > On Fri, Feb 22, 2008 at 6:02 AM, Curt Hagenlocher > wrote: > > > Ah, no. I was thinking that you would modify your VB code to launch it > > as a console app (for instance) rather than from inside of ASP.NET-- and see if you still get the same error. > > > > > > On Thu, Feb 21, 2008 at 10:07 PM, Howland-Rose, Kyle < > > Kyle.Howland-Rose at aar.com.au> wrote: > > > > > Thanks for your help so late Curt (not that I need a quick answer at > > > all). > > > > > > I am sure I am missing something big-time here and "talking" as > > > cross-purposes, but, to my mind the reason I don't have a problem when > > > running from the command line is because all I am doing is running the > > > ipy.exe on the file which loads some assemblies, creates a class > > > definition and a function definition and then terminates without even > > > instantiating the class. Is this what you mean by "running it > > > directly"? > > > > > > Thanks again, > > > Kyle > > > > > > ------------------------------ > > > *From:* users-bounces at lists.ironpython.com [mailto: > > > users-bounces at lists.ironpython.com] *On Behalf Of *Curt Hagenlocher > > > *Sent:* Friday, 22 February 2008 4:55 PM > > > *To:* Discussion of IronPython > > > *Subject:* Re: [IronPython] FW: FW: returning inherited classes to > > > .NET > > > > > > If you're only getting the error under ASP.NET , > > > then it's highly likely that you're loading multiple copies of the same > > > assembly, which is why the CLR can't cast your Python class back to the VB > > > base -- it literally considers them to be two different classes. This may > > > be related to the way ASP.NET makes shadow copies of > > > your files, but there could be other reasons as well (none of which, > > > unfortunately, come to mind right now). > > > > > > Using an interface instead of a base class would give you the same > > > results. > > > On Thu, Feb 21, 2008 at 9:44 PM, Howland-Rose, Kyle < > > > Kyle.Howland-Rose at aar.com.au> wrote: > > > > > > > It runs fine from the command line but then it does not do much ... > > > > yet. For the moment I am simplifying it by removing IP :( > > > > > > > > I wanted to so some moderately heavy reflection which to my thinking > > > > should be easier from IP but I will use VB for now. > > > > > > > > I assume I *should* be able to return a derived python class to VB? > > > > Alternatively I could implement an interface. How can IP implement a .NET > > > > interface? > > > > (All pointers to pre-existing doco warmly received :) > > > > > > > > Thanks > > > > Kyle > > > > > > > > ------------------------------ > > > > *From:* users-bounces at lists.ironpython.com [mailto: > > > > users-bounces at lists.ironpython.com] *On Behalf Of *Curt Hagenlocher > > > > *Sent:* Friday, 22 February 2008 4:29 PM > > > > *To:* Discussion of IronPython > > > > *Subject:* Re: [IronPython] FW: returning inherited classes to .NET > > > > > > > > My apologies; I wasn't reading the code correctly. That's > > > > probably a sign that I should be going to bed. :) Have you tried > > > > simplifying your version just a little bit by running it directly rather > > > > than through ASP.NET ? > > > > > > > > > > > > On Thu, Feb 21, 2008 at 8:43 PM, Howland-Rose, Kyle < > > > > Kyle.Howland-Rose at aar.com.au> wrote: > > > > > > > > > Hi Curt, > > > > > > > > > > Thanks for replying. When I view the link I see the following: > > > > > > > > > > The .NET code creates the "Test" class and then runs the python > > > > > code > > > > > which imports the "Test" class a subclasses it to create python > > > > > class > > > > > "X". > > > > > > > > > > Class "X" is then called and cast to type "Test" and assigned to > > > > > the > > > > > value obj. > > > > > > > > > > Is this what you are looking at? > > > > > > > > > > My code is pretty much identical. The VB looks like: > > > > > > > > > > > > > > > Public MustInherit Class ChildControl > > > > > Public Function Control() As WebControl > > > > > Return Nothing > > > > > End Function > > > > > Public Function GetValue() As String > > > > > Return Nothing > > > > > End Function > > > > > Public Function SetValue(ByVal value As Object) As String > > > > > Return Nothing > > > > > End Function > > > > > End Class > > > > > > > > > > Class IPReflection > > > > > Private Shared Instance As IPReflection = Nothing > > > > > Private PyEngine As PythonEngine > > > > > Private PyModule As EngineModule > > > > > > > > > > Public Shared Function Inst() As IPReflection > > > > > If Instance Is Nothing Then > > > > > Instance = New IPReflection > > > > > End If > > > > > Return Instance > > > > > End Function > > > > > > > > > > Private Sub New() > > > > > Dim path As String = HttpContext.Current.Request.MapPath > > > > > (".") > > > > > PyEngine = New PythonEngine > > > > > PyEngine.AddToPath(path) > > > > > PyModule = PyEngine.CreateModule > > > > > PyEngine.DefaultModule = PyModule > > > > > > > > > > PyEngine.ExecuteFile(HttpContext.Current.Request.MapPath > > > > > ("CustomControls > > > > > .py")) > > > > > End Sub > > > > > > > > > > Public Function GetChildControl() As ChildControl > > > > > Return > > > > > CType(Operations.Ops.Call(PyModule.Globals("GetControl")), > > > > > ChildControl) > > > > > End Function > > > > > End Class > > > > > > > > > > And the python looks like: > > > > > > > > > > import clr > > > > > import sys > > > > > > > > > > clr.AddReference('System') > > > > > import System > > > > > > > > > > sys.path.append(sys.path[0] + "/bin") > > > > > > > > > > clr.AddReferenceToFile("WebControlLibrary.dll") > > > > > clr.AddReference('System.Web') > > > > > > > > > > from System.Web.UI.WebControls import Label > > > > > > > > > > from WebControlLibrary import ChildControl > > > > > > > > > > class LabelChildControl(ChildControl): > > > > > def __init__(self): > > > > > self.control = Label() > > > > > def Control(self): > > > > > return self.control > > > > > > > > > > def GetControl(): > > > > > return LabelChildControl() > > > > > > > > > > > > > > > Thanks again, > > > > > Kyle > > > > > > > > > > ________________________________ > > > > > > > > > > From: users-bounces at lists.ironpython.com > > > > > [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt > > > > > Hagenlocher > > > > > Sent: Friday, 22 February 2008 3:08 PM > > > > > To: Discussion of IronPython > > > > > Subject: Re: [IronPython] returning inherited classes to .NET > > > > > > > > > > > > > > > The page in question doesn't seem to show what you describe -- > > > > > deriving > > > > > a Python class from a C# class. Maybe you could show us your > > > > > sample > > > > > code? > > > > > > > > > > > > > > > On Thu, Feb 21, 2008 at 7:39 PM, Howland-Rose, Kyle > > > > > wrote: > > > > > > > > > > > > > > > Hi all, > > > > > I am following > > > > > > > > > > > > > > > > > > > > http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET > > > > > < > > > > > http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET > > > > > > > > > > > but using VB. > > > > > > > > > > In VB I declare a class and derive a python 1.1 class from > > > > > it > > > > > but when I return it I get the exception: > > > > > > > > > > "Unable to cast object of type > > > > > 'IronPython.NewTypes.WebControlLibrary.ChildControl_1' to type > > > > > 'WebControlLibrary.ChildControl'." > > > > > > > > > > The page referenced above just seems to cast the python > > > > > class > > > > > instance to the C# class instance but this does not work for me in > > > > > VB. > > > > > > > > > > Any help would be appreciated :) > > > > > > > > > > Thanks, > > > > > > > > > > Kyle > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > > > > > > > > > > This email is confidential and may be subject to legal or > > > > > other > > > > > professional privilege. It is also subject to copyright. If you > > > > > have > > > > > received it in error, confidentiality and privilege are not waived > > > > > and > > > > > you must not disclose or use the information in it. Please notify > > > > > the > > > > > sender by return email and delete it from your system. Any > > > > > personal > > > > > information in this email must be handled in accordance with the > > > > > Privacy > > > > > Act 1988 (Cth). > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > * > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > > > > > > > > > > This email is confidential and may be subject to legal or > > > > > other > > > > > professional privilege. It is also subject to copyright. If you > > > > > have > > > > > received it in error, confidentiality and privilege are not waived > > > > > and > > > > > you must not disclose or use the information in it. Please notify > > > > > the > > > > > sender by return email and delete it from your system. Any > > > > > personal > > > > > information in this email must be handled in accordance with the > > > > > Privacy > > > > > Act 1988 (Cth). > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > * > > > > > > > > > > > > > > > _______________________________________________ > > > > > Users mailing list > > > > > Users at lists.ironpython.com > > > > > > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > _______________________________________________ > > > > > Users mailing list > > > > > Users at lists.ironpython.com > > > > > > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > > > > > This email is confidential and may be subject to legal or other > > > > > professional privilege. It is also subject to copyright. If you have > > > > > received it in error, confidentiality and privilege are not waived and you > > > > > must not disclose or use the information in it. Please notify the sender by > > > > > return email and delete it from your system. Any personal information in > > > > > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > > > > > > > > > > > > > > ************************************************************************* > > > > > > > > > > _______________________________________________ > > > > > Users mailing list > > > > > Users at lists.ironpython.com > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > _______________________________________________ > > > > > Users mailing list > > > > > Users at lists.ironpython.com > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > > > This email is confidential and may be subject to legal or other > > > > professional privilege. It is also subject to copyright. If you have > > > > received it in error, confidentiality and privilege are not waived and you > > > > must not disclose or use the information in it. Please notify the sender by > > > > return email and delete it from your system. Any personal information in > > > > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > > > > > > > > > > > ************************************************************************* > > > > > > > > _______________________________________________ > > > > Users mailing list > > > > Users at lists.ironpython.com > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > _______________________________________________ > > > > Users mailing list > > > > Users at lists.ironpython.com > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > This email is confidential and may be subject to legal or other > > > professional privilege. It is also subject to copyright. If you have > > > received it in error, confidentiality and privilege are not waived and you > > > must not disclose or use the information in it. Please notify the sender by > > > return email and delete it from your system. Any personal information in > > > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > > > > > > > > ************************************************************************* > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > _______________________________________________ > > > Users mailing list > > > Users at lists.ironpython.com > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > ************************************************************************ > > Allens Arthur Robinson online: http://www.aar.com.au > > This email is confidential and may be subject to legal or other > professional privilege. It is also subject to copyright. If you have > received it in error, confidentiality and privilege are not waived and you > must not disclose or use the information in it. Please notify the sender by > return email and delete it from your system. Any personal information in > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > ************************************************************************* > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Kyle.Howland-Rose at aar.com.au Mon Feb 25 00:47:04 2008 From: Kyle.Howland-Rose at aar.com.au (Howland-Rose, Kyle) Date: Mon, 25 Feb 2008 10:47:04 +1100 Subject: [IronPython] Returning inherited classes to .NET In-Reply-To: Message-ID: <204557C1883DCD40B4F8039D8E3C3B0827E994@SYDEXCVS0.aar.com.au> Is there a good place to read about these variants? ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Monday, 25 February 2008 10:31 AM To: Discussion of IronPython Subject: Re: [IronPython] Returning inherited classes to .NET It's a feature. clr.AddReferenceToFile ends up calling Assembly.LoadFile under the covers, which lets you load multiple versions of the same assembly. If this isn't the behavior you want, you should use a differently variant of AddReference (such as clr.AddReference). Each variant has its uses; this one's don't correspond well with your intentions. On Sun, Feb 24, 2008 at 2:22 PM, Howland-Rose, Kyle wrote: Awesome, thanks Curt. Do you have any idea as to whether this is a bug or a feature? ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Saturday, 23 February 2008 1:33 AM To: Discussion of IronPython Subject: Re: [IronPython] FW: FW: FW: returning inherited classes to .NET I built a test executable and was able to reproduce this. And when I changed clr.AddReferenceToFile("WebControlLibrary.dll") to clr.AddReference("WebControlLibrary") it worked as expected. On Fri, Feb 22, 2008 at 6:02 AM, Curt Hagenlocher wrote: Ah, no. I was thinking that you would modify your VB code to launch it as a console app (for instance) rather than from inside of ASP.NET -- and see if you still get the same error. On Thu, Feb 21, 2008 at 10:07 PM, Howland-Rose, Kyle wrote: Thanks for your help so late Curt (not that I need a quick answer at all). I am sure I am missing something big-time here and "talking" as cross-purposes, but, to my mind the reason I don't have a problem when running from the command line is because all I am doing is running the ipy.exe on the file which loads some assemblies, creates a class definition and a function definition and then terminates without even instantiating the class. Is this what you mean by "running it directly"? Thanks again, Kyle ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Friday, 22 February 2008 4:55 PM To: Discussion of IronPython Subject: Re: [IronPython] FW: FW: returning inherited classes to .NET If you're only getting the error under ASP.NET , then it's highly likely that you're loading multiple copies of the same assembly, which is why the CLR can't cast your Python class back to the VB base -- it literally considers them to be two different classes. This may be related to the way ASP.NET makes shadow copies of your files, but there could be other reasons as well (none of which, unfortunately, come to mind right now). Using an interface instead of a base class would give you the same results. On Thu, Feb 21, 2008 at 9:44 PM, Howland-Rose, Kyle wrote: It runs fine from the command line but then it does not do much ... yet. For the moment I am simplifying it by removing IP :( I wanted to so some moderately heavy reflection which to my thinking should be easier from IP but I will use VB for now. I assume I *should* be able to return a derived python class to VB? Alternatively I could implement an interface. How can IP implement a .NET interface? (All pointers to pre-existing doco warmly received :) Thanks Kyle ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Friday, 22 February 2008 4:29 PM To: Discussion of IronPython Subject: Re: [IronPython] FW: returning inherited classes to .NET My apologies; I wasn't reading the code correctly. That's probably a sign that I should be going to bed. :) Have you tried simplifying your version just a little bit by running it directly rather than through ASP.NET ? On Thu, Feb 21, 2008 at 8:43 PM, Howland-Rose, Kyle wrote: Hi Curt, Thanks for replying. When I view the link I see the following: The .NET code creates the "Test" class and then runs the python code which imports the "Test" class a subclasses it to create python class "X". Class "X" is then called and cast to type "Test" and assigned to the value obj. Is this what you are looking at? My code is pretty much identical. The VB looks like: Public MustInherit Class ChildControl Public Function Control() As WebControl Return Nothing End Function Public Function GetValue() As String Return Nothing End Function Public Function SetValue(ByVal value As Object) As String Return Nothing End Function End Class Class IPReflection Private Shared Instance As IPReflection = Nothing Private PyEngine As PythonEngine Private PyModule As EngineModule Public Shared Function Inst() As IPReflection If Instance Is Nothing Then Instance = New IPReflection End If Return Instance End Function Private Sub New() Dim path As String = HttpContext.Current.Request.MapPath(".") PyEngine = New PythonEngine PyEngine.AddToPath(path) PyModule = PyEngine.CreateModule PyEngine.DefaultModule = PyModule PyEngine.ExecuteFile(HttpContext.Current.Request.MapPath("CustomControls .py")) End Sub Public Function GetChildControl() As ChildControl Return CType(Operations.Ops.Call(PyModule.Globals("GetControl")), ChildControl) End Function End Class And the python looks like: import clr import sys clr.AddReference('System') import System sys.path.append(sys.path[0] + "/bin") clr.AddReferenceToFile("WebControlLibrary.dll") clr.AddReference('System.Web') from System.Web.UI.WebControls import Label from WebControlLibrary import ChildControl class LabelChildControl(ChildControl): def __init__(self): self.control = Label() def Control(self): return self.control def GetControl(): return LabelChildControl() Thanks again, Kyle ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Friday, 22 February 2008 3:08 PM To: Discussion of IronPython Subject: Re: [IronPython] returning inherited classes to .NET The page in question doesn't seem to show what you describe -- deriving a Python class from a C# class. Maybe you could show us your sample code? On Thu, Feb 21, 2008 at 7:39 PM, Howland-Rose, Kyle wrote: Hi all, I am following http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET but using VB. In VB I declare a class and derive a python 1.1 class from it but when I return it I get the exception: "Unable to cast object of type 'IronPython.NewTypes.WebControlLibrary.ChildControl_1' to type 'WebControlLibrary.ChildControl'." The page referenced above just seems to cast the python class instance to the C# class instance but this does not work for me in VB. Any help would be appreciated :) Thanks, Kyle ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************* -------------- next part -------------- An HTML attachment was scrubbed... URL: From Kyle.Howland-Rose at aar.com.au Mon Feb 25 01:00:01 2008 From: Kyle.Howland-Rose at aar.com.au (Howland-Rose, Kyle) Date: Mon, 25 Feb 2008 11:00:01 +1100 Subject: [IronPython] FW: Returning inherited classes to .NET Message-ID: <204557C1883DCD40B4F8039D8E3C3B0827E995@SYDEXCVS0.aar.com.au> Is there a good place to read about these variants? I was using this one because I did not want to use the GAC and AddReference failed just using "WebControlLibrary" presumably because I needed to add the dll's path to a path list somewhere. ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Monday, 25 February 2008 10:31 AM To: Discussion of IronPython Subject: Re: [IronPython] Returning inherited classes to .NET It's a feature. clr.AddReferenceToFile ends up calling Assembly.LoadFile under the covers, which lets you load multiple versions of the same assembly. If this isn't the behavior you want, you should use a differently variant of AddReference (such as clr.AddReference). Each variant has its uses; this one's don't correspond well with your intentions. On Sun, Feb 24, 2008 at 2:22 PM, Howland-Rose, Kyle < Kyle.Howland-Rose at aar.com.au> wrote: Awesome, thanks Curt. Do you have any idea as to whether this is a bug or a feature? ________________________________ From: users-bounces at lists.ironpython.com [mailto: users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Saturday, 23 February 2008 1:33 AM To: Discussion of IronPython Subject: Re: [IronPython] FW: FW: FW: returning inherited classes to .NET I built a test executable and was able to reproduce this. And when I changed clr.AddReferenceToFile("WebControlLibrary.dll") to clr.AddReference("WebControlLibrary") it worked as expected. On Fri, Feb 22, 2008 at 6:02 AM, Curt Hagenlocher < curt at hagenlocher.org> wrote: Ah, no. I was thinking that you would modify your VB code to launch it as a console app (for instance) rather than from inside of ASP.NET -- and see if you still get the same error. On Thu, Feb 21, 2008 at 10:07 PM, Howland-Rose, Kyle < Kyle.Howland-Rose at aar.com.au> wrote: Thanks for your help so late Curt (not that I need a quick answer at all). I am sure I am missing something big-time here and "talking" as cross-purposes, but, to my mind the reason I don't have a problem when running from the command line is because all I am doing is running the ipy.exe on the file which loads some assemblies, creates a class definition and a function definition and then terminates without even instantiating the class. Is this what you mean by "running it directly"? Thanks again, Kyle ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Friday, 22 February 2008 4:55 PM To: Discussion of IronPython Subject: Re: [IronPython] FW: FW: returning inherited classes to .NET If you're only getting the error under ASP.NET , then it's highly likely that you're loading multiple copies of the same assembly, which is why the CLR can't cast your Python class back to the VB base -- it literally considers them to be two different classes. This may be related to the way ASP.NET makes shadow copies of your files, but there could be other reasons as well (none of which, unfortunately, come to mind right now). Using an interface instead of a base class would give you the same results. On Thu, Feb 21, 2008 at 9:44 PM, Howland-Rose, Kyle wrote: It runs fine from the command line but then it does not do much ... yet. For the moment I am simplifying it by removing IP :( I wanted to so some moderately heavy reflection which to my thinking should be easier from IP but I will use VB for now. I assume I *should* be able to return a derived python class to VB? Alternatively I could implement an interface. How can IP implement a .NET interface? (All pointers to pre-existing doco warmly received :) Thanks Kyle ________________________________ From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Friday, 22 February 2008 4:29 PM To: Discussion of IronPython Subject: Re: [IronPython] FW: returning inherited classes to .NET My apologies; I wasn't reading the code correctly. That's probably a sign that I should be going to bed. :) Have you tried simplifying your version just a little bit by running it directly rather than through ASP.NET ? On Thu, Feb 21, 2008 at 8:43 PM, Howland-Rose, Kyle wrote: Hi Curt, Thanks for replying. When I view the link I see the following: The .NET code creates the "Test" class and then runs the python code which imports the "Test" class a subclasses it to create python class "X". Class "X" is then called and cast to type "Test" and assigned to the value obj. Is this what you are looking at? My code is pretty much identical. The VB looks like: Public MustInherit Class ChildControl Public Function Control() As WebControl Return Nothing End Function Public Function GetValue() As String Return Nothing End Function Public Function SetValue(ByVal value As Object) As String Return Nothing End Function End Class Class IPReflection Private Shared Instance As IPReflection = Nothing Private PyEngine As PythonEngine Private PyModule As EngineModule Public Shared Function Inst() As IPReflection If Instance Is Nothing Then Instance = New IPReflection End If Return Instance End Function Private Sub New() Dim path As String = HttpContext.Current.Request.MapPath(".") PyEngine = New PythonEngine PyEngine.AddToPath(path) PyModule = PyEngine.CreateModule PyEngine.DefaultModule = PyModule PyEngine.ExecuteFile(HttpContext.Current.Request.MapPath("CustomControls .py")) End Sub Public Function GetChildControl() As ChildControl Return CType(Operations.Ops.Call(PyModule.Globals("GetControl")), ChildControl) End Function End Class And the python looks like: import clr import sys clr.AddReference('System') import System sys.path.append(sys.path[0] + "/bin") clr.AddReferenceToFile("WebControlLibrary.dll") clr.AddReference('System.Web') from System.Web.UI.WebControls import Label from WebControlLibrary import ChildControl class LabelChildControl(ChildControl): def __init__(self): self.control = Label() def Control(self): return self.control def GetControl(): return LabelChildControl() Thanks again, Kyle ________________________________ From: users-bounces at lists.ironpython.com [mailto: users-bounces at lists.ironpython.com] On Behalf Of Curt Hagenlocher Sent: Friday, 22 February 2008 3:08 PM To: Discussion of IronPython Subject: Re: [IronPython] returning inherited classes to .NET The page in question doesn't seem to show what you describe -- deriving a Python class from a C# class. Maybe you could show us your sample code? On Thu, Feb 21, 2008 at 7:39 PM, Howland-Rose, Kyle wrote: Hi all, I am following http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET < http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET> but using VB. In VB I declare a class and derive a python 1.1 class from it but when I return it I get the exception: "Unable to cast object of type 'IronPython.NewTypes.WebControlLibrary.ChildControl_1' to type 'WebControlLibrary.ChildControl'." The page referenced above just seems to cast the python class instance to the C# class instance but this does not work for me in VB. Any help would be appreciated :) Thanks, Kyle ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************ * _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com ************************************************************************ Allens Arthur Robinson online: http://www.aar.com.au This email is confidential and may be subject to legal or other professional privilege. It is also subject to copyright. If you have received it in error, confidentiality and privilege are not waived and you must not disclose or use the information in it. Please notify the sender by return email and delete it from your system. Any personal information in this email must be handled in accordance with the Privacy Act 1988 (Cth). ************************************************************************* -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: ATT621932.txt URL: From curt at hagenlocher.org Mon Feb 25 01:09:39 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Sun, 24 Feb 2008 16:09:39 -0800 Subject: [IronPython] FW: Returning inherited classes to .NET In-Reply-To: <204557C1883DCD40B4F8039D8E3C3B0827E995@SYDEXCVS0.aar.com.au> References: <204557C1883DCD40B4F8039D8E3C3B0827E995@SYDEXCVS0.aar.com.au> Message-ID: http://blogs.msdn.com/haibo_luo/archive/2007/09/25/5130072.aspx On Sun, Feb 24, 2008 at 4:00 PM, Howland-Rose, Kyle < Kyle.Howland-Rose at aar.com.au> wrote: > Is there a good place to read about these variants? I was using this > one because I did not want to use the GAC and AddReference failed just using > "WebControlLibrary" presumably because I needed to add the dll's path to a > path list somewhere. > > ------------------------------ > *From:* users-bounces at lists.ironpython.com [mailto: > users-bounces at lists.ironpython.com] *On Behalf Of *Curt Hagenlocher > *Sent:* Monday, 25 February 2008 10:31 AM > *To:* Discussion of IronPython > *Subject:* Re: [IronPython] Returning inherited classes to .NET > > It's a feature. clr.AddReferenceToFile ends up calling > Assembly.LoadFile under the covers, which lets you load multiple versions > of the same assembly. If this isn't the behavior you want, you should use a > differently variant of AddReference (such as clr.AddReference). Each > variant has its uses; this one's don't correspond well with your intentions. > > On Sun, Feb 24, 2008 at 2:22 PM, Howland-Rose, Kyle < > Kyle.Howland-Rose at aar.com.au> wrote: > > > Awesome, thanks Curt. > > > > Do you have any idea as to whether this is a bug or a feature? > > > > ------------------------------ > > *From:* users-bounces at lists.ironpython.com [mailto: > > users-bounces at lists.ironpython.com] *On Behalf Of *Curt Hagenlocher > > *Sent:* Saturday, 23 February 2008 1:33 AM > > *To:* Discussion of IronPython > > *Subject:* Re: [IronPython] FW: FW: FW: returning inherited classes to > > .NET > > > > I built a test executable and was able to reproduce this. And when I > > changed > > clr.AddReferenceToFile("WebControlLibrary.dll") > > to > > clr.AddReference("WebControlLibrary") > > it worked as expected. > > On Fri, Feb 22, 2008 at 6:02 AM, Curt Hagenlocher > > wrote: > > > > > Ah, no. I was thinking that you would modify your VB code to launch > > > it as a console app (for instance) rather than from inside of ASP.NET-- and see if you still get the same error. > > > > > > > > > On Thu, Feb 21, 2008 at 10:07 PM, Howland-Rose, Kyle < > > > Kyle.Howland-Rose at aar.com.au> wrote: > > > > > > > Thanks for your help so late Curt (not that I need a quick answer > > > > at all). > > > > > > > > I am sure I am missing something big-time here and "talking" as > > > > cross-purposes, but, to my mind the reason I don't have a problem when > > > > running from the command line is because all I am doing is running the > > > > ipy.exe on the file which loads some assemblies, creates a class > > > > definition and a function definition and then terminates without even > > > > instantiating the class. Is this what you mean by "running it > > > > directly"? > > > > > > > > Thanks again, > > > > Kyle > > > > > > > > ------------------------------ > > > > *From:* users-bounces at lists.ironpython.com [mailto: > > > > users-bounces at lists.ironpython.com] *On Behalf Of *Curt Hagenlocher > > > > *Sent:* Friday, 22 February 2008 4:55 PM > > > > *To:* Discussion of IronPython > > > > *Subject:* Re: [IronPython] FW: FW: returning inherited classes to > > > > .NET > > > > > > > > If you're only getting the error under ASP.NET , > > > > then it's highly likely that you're loading multiple copies of the same > > > > assembly, which is why the CLR can't cast your Python class back to the VB > > > > base -- it literally considers them to be two different classes. This may > > > > be related to the way ASP.NET makes shadow copies > > > > of your files, but there could be other reasons as well (none of which, > > > > unfortunately, come to mind right now). > > > > > > > > Using an interface instead of a base class would give you the same > > > > results. > > > > On Thu, Feb 21, 2008 at 9:44 PM, Howland-Rose, Kyle < > > > > Kyle.Howland-Rose at aar.com.au> wrote: > > > > > > > > > It runs fine from the command line but then it does not do much > > > > > ... yet. For the moment I am simplifying it by removing IP :( > > > > > > > > > > I wanted to so some moderately heavy reflection which to my > > > > > thinking should be easier from IP but I will use VB for now. > > > > > > > > > > I assume I *should* be able to return a derived python class to > > > > > VB? Alternatively I could implement an interface. How can IP implement a > > > > > .NET interface? > > > > > (All pointers to pre-existing doco warmly received :) > > > > > > > > > > Thanks > > > > > Kyle > > > > > > > > > > ------------------------------ > > > > > *From:* users-bounces at lists.ironpython.com [mailto: > > > > > users-bounces at lists.ironpython.com] *On Behalf Of *Curt > > > > > Hagenlocher > > > > > *Sent:* Friday, 22 February 2008 4:29 PM > > > > > *To:* Discussion of IronPython > > > > > *Subject:* Re: [IronPython] FW: returning inherited classes to > > > > > .NET > > > > > > > > > > My apologies; I wasn't reading the code correctly. That's > > > > > probably a sign that I should be going to bed. :) Have you tried > > > > > simplifying your version just a little bit by running it directly rather > > > > > than through ASP.NET ? > > > > > > > > > > > > > > > On Thu, Feb 21, 2008 at 8:43 PM, Howland-Rose, Kyle < > > > > > Kyle.Howland-Rose at aar.com.au> wrote: > > > > > > > > > > > Hi Curt, > > > > > > > > > > > > Thanks for replying. When I view the link I see the following: > > > > > > > > > > > > The .NET code creates the "Test" class and then runs the python > > > > > > code > > > > > > which imports the "Test" class a subclasses it to create python > > > > > > class > > > > > > "X". > > > > > > > > > > > > Class "X" is then called and cast to type "Test" and assigned to > > > > > > the > > > > > > value obj. > > > > > > > > > > > > Is this what you are looking at? > > > > > > > > > > > > My code is pretty much identical. The VB looks like: > > > > > > > > > > > > > > > > > > Public MustInherit Class ChildControl > > > > > > Public Function Control() As WebControl > > > > > > Return Nothing > > > > > > End Function > > > > > > Public Function GetValue() As String > > > > > > Return Nothing > > > > > > End Function > > > > > > Public Function SetValue(ByVal value As Object) As String > > > > > > Return Nothing > > > > > > End Function > > > > > > End Class > > > > > > > > > > > > Class IPReflection > > > > > > Private Shared Instance As IPReflection = Nothing > > > > > > Private PyEngine As PythonEngine > > > > > > Private PyModule As EngineModule > > > > > > > > > > > > Public Shared Function Inst() As IPReflection > > > > > > If Instance Is Nothing Then > > > > > > Instance = New IPReflection > > > > > > End If > > > > > > Return Instance > > > > > > End Function > > > > > > > > > > > > Private Sub New() > > > > > > Dim path As String = HttpContext.Current.Request.MapPath > > > > > > (".") > > > > > > PyEngine = New PythonEngine > > > > > > PyEngine.AddToPath(path) > > > > > > PyModule = PyEngine.CreateModule > > > > > > PyEngine.DefaultModule = PyModule > > > > > > > > > > > > PyEngine.ExecuteFile(HttpContext.Current.Request.MapPath > > > > > > ("CustomControls > > > > > > .py")) > > > > > > End Sub > > > > > > > > > > > > Public Function GetChildControl() As ChildControl > > > > > > Return > > > > > > CType(Operations.Ops.Call(PyModule.Globals("GetControl")), > > > > > > ChildControl) > > > > > > End Function > > > > > > End Class > > > > > > > > > > > > And the python looks like: > > > > > > > > > > > > import clr > > > > > > import sys > > > > > > > > > > > > clr.AddReference('System') > > > > > > import System > > > > > > > > > > > > sys.path.append(sys.path[0] + "/bin") > > > > > > > > > > > > clr.AddReferenceToFile("WebControlLibrary.dll") > > > > > > clr.AddReference('System.Web') > > > > > > > > > > > > from System.Web.UI.WebControls import Label > > > > > > > > > > > > from WebControlLibrary import ChildControl > > > > > > > > > > > > class LabelChildControl(ChildControl): > > > > > > def __init__(self): > > > > > > self.control = Label() > > > > > > def Control(self): > > > > > > return self.control > > > > > > > > > > > > def GetControl(): > > > > > > return LabelChildControl() > > > > > > > > > > > > > > > > > > Thanks again, > > > > > > Kyle > > > > > > > > > > > > ________________________________ > > > > > > > > > > > > From: users-bounces at lists.ironpython.com > > > > > > [mailto:users-bounces at lists.ironpython.com] On Behalf Of Curt > > > > > > Hagenlocher > > > > > > Sent: Friday, 22 February 2008 3:08 PM > > > > > > To: Discussion of IronPython > > > > > > Subject: Re: [IronPython] returning inherited classes to .NET > > > > > > > > > > > > > > > > > > The page in question doesn't seem to show what you describe -- > > > > > > deriving > > > > > > a Python class from a C# class. Maybe you could show us your > > > > > > sample > > > > > > code? > > > > > > > > > > > > > > > > > > On Thu, Feb 21, 2008 at 7:39 PM, Howland-Rose, Kyle > > > > > > wrote: > > > > > > > > > > > > > > > > > > Hi all, > > > > > > I am following > > > > > > > > > > > > > > > > > > > > > > > > http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET > > > > > > < > > > > > > http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET > > > > > > > > > > > > > but using VB. > > > > > > > > > > > > In VB I declare a class and derive a python 1.1 class > > > > > > from it > > > > > > but when I return it I get the exception: > > > > > > > > > > > > "Unable to cast object of type > > > > > > 'IronPython.NewTypes.WebControlLibrary.ChildControl_1' to type > > > > > > 'WebControlLibrary.ChildControl'." > > > > > > > > > > > > The page referenced above just seems to cast the python > > > > > > class > > > > > > instance to the C# class instance but this does not work for me > > > > > > in VB. > > > > > > > > > > > > Any help would be appreciated :) > > > > > > > > > > > > Thanks, > > > > > > > > > > > > Kyle > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > > > > > > > > > > > > > This email is confidential and may be subject to legal or > > > > > > other > > > > > > professional privilege. It is also subject to copyright. If you > > > > > > have > > > > > > received it in error, confidentiality and privilege are not > > > > > > waived and > > > > > > you must not disclose or use the information in it. Please > > > > > > notify the > > > > > > sender by return email and delete it from your system. Any > > > > > > personal > > > > > > information in this email must be handled in accordance with the > > > > > > Privacy > > > > > > Act 1988 (Cth). > > > > > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > * > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > > > > > > > > > > > > > This email is confidential and may be subject to legal or > > > > > > other > > > > > > professional privilege. It is also subject to copyright. If you > > > > > > have > > > > > > received it in error, confidentiality and privilege are not > > > > > > waived and > > > > > > you must not disclose or use the information in it. Please > > > > > > notify the > > > > > > sender by return email and delete it from your system. Any > > > > > > personal > > > > > > information in this email must be handled in accordance with the > > > > > > Privacy > > > > > > Act 1988 (Cth). > > > > > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > * > > > > > > > > > > > > > > > > > > _______________________________________________ > > > > > > Users mailing list > > > > > > Users at lists.ironpython.com > > > > > > > > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > _______________________________________________ > > > > > > Users mailing list > > > > > > Users at lists.ironpython.com > > > > > > > > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > > > > > > > This email is confidential and may be subject to legal or other > > > > > > professional privilege. It is also subject to copyright. If you have > > > > > > received it in error, confidentiality and privilege are not waived and you > > > > > > must not disclose or use the information in it. Please notify the sender by > > > > > > return email and delete it from your system. Any personal information in > > > > > > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > > > > > > > > > > > > > > > > > ************************************************************************* > > > > > > > > > > > > _______________________________________________ > > > > > > Users mailing list > > > > > > Users at lists.ironpython.com > > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > _______________________________________________ > > > > > > Users mailing list > > > > > > Users at lists.ironpython.com > > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > > > > > This email is confidential and may be subject to legal or other > > > > > professional privilege. It is also subject to copyright. If you have > > > > > received it in error, confidentiality and privilege are not waived and you > > > > > must not disclose or use the information in it. Please notify the sender by > > > > > return email and delete it from your system. Any personal information in > > > > > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > > > > > > > > > > > > > > ************************************************************************* > > > > > > > > > > _______________________________________________ > > > > > Users mailing list > > > > > Users at lists.ironpython.com > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > _______________________________________________ > > > > > Users mailing list > > > > > Users at lists.ironpython.com > > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > > > > > > > > > > > > > ************************************************************************ > > > > > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > > > > > This email is confidential and may be subject to legal or other > > > > professional privilege. It is also subject to copyright. If you have > > > > received it in error, confidentiality and privilege are not waived and you > > > > must not disclose or use the information in it. Please notify the sender by > > > > return email and delete it from your system. Any personal information in > > > > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > > > > > > > > > > > ************************************************************************* > > > > > > > > _______________________________________________ > > > > Users mailing list > > > > Users at lists.ironpython.com > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > _______________________________________________ > > > > Users mailing list > > > > Users at lists.ironpython.com > > > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > > > > > > > > > > ************************************************************************ > > > > Allens Arthur Robinson online: http://www.aar.com.au > > > > This email is confidential and may be subject to legal or other > > professional privilege. It is also subject to copyright. If you have > > received it in error, confidentiality and privilege are not waived and you > > must not disclose or use the information in it. Please notify the sender by > > return email and delete it from your system. Any personal information in > > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > > > > > ************************************************************************* > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > _______________________________________________ > > Users mailing list > > Users at lists.ironpython.com > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > ************************************************************************ > > Allens Arthur Robinson online: http://www.aar.com.au > > This email is confidential and may be subject to legal or other > professional privilege. It is also subject to copyright. If you have > received it in error, confidentiality and privilege are not waived and you > must not disclose or use the information in it. Please notify the sender by > return email and delete it from your system. Any personal information in > this email must be handled in accordance with the Privacy Act 1988 (Cth). > > ************************************************************************* > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jigisbert.etra-id at grupoetra.com Tue Feb 26 07:32:27 2008 From: jigisbert.etra-id at grupoetra.com (Jose Ignacio Gisbert) Date: Tue, 26 Feb 2008 07:32:27 +0100 Subject: [IronPython] How to import python folders as modules Message-ID: <000f01c87841$5b885d90$2a021fac@depid.local> Hi all, IronPython Works well when you import python .py modules, but when you import python modules as folders (as xmpp), it does not recognize them. Someone knows how to do it? Thanks in advance, Best Regards, Ignacio -------------- next part -------------- An HTML attachment was scrubbed... URL: From stalya at zeomega.com Tue Feb 26 12:47:21 2008 From: stalya at zeomega.com (Suma Talya) Date: Tue, 26 Feb 2008 17:17:21 +0530 Subject: [IronPython] Exporting Python code as an assembly Message-ID: <47C3FC49.3030500@zeomega.com> Hi, I have a py file by name IronPythonDLL.py containing --------------------------------------------------------------- import clr import System import sys from ClrWrapper import ClrAttribute, ClrAccepts, ClrReturns class IronPythonClass: clr_namespace = 'IronPythonDLL' @ClrReturns(System.String) def IPyMethod(self): return "IronPython Method" --------------------------------------------------------------- I have created IronPythonDLL.dll using MakeModule.py Now through ironpython interpreter i tried creating an instance of the above class and got an error, >>> import clr >>> clr.AddReference('IronPythonDLL.dll') >>> import IronPythonDLL >>> o=IronPythonDLL.IronPythonClass() Traceback (most recent call last): File IronPythonDLL, line unknown, in .ctor File IronPythonDLL, line unknown, in InitClass File , line unknown, in ##26 TypeError: Value cannot be null. Parameter name: scriptSource Any help on this will be useful.... Thanks, -Suma. From dinov at exchange.microsoft.com Tue Feb 26 17:59:29 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Tue, 26 Feb 2008 08:59:29 -0800 Subject: [IronPython] How to import python folders as modules In-Reply-To: <000f01c87841$5b885d90$2a021fac@depid.local> References: <000f01c87841$5b885d90$2a021fac@depid.local> Message-ID: <7AD436E4270DD54A94238001769C2227011CF570C276@DF-GRTDANE-MSG.exchange.corp.microsoft.com> As long as there's an __init__.py we should recognize it as a module. If by xmpp you're referring to PyXMPP at http://pyxmpp.jajcus.net/ then it looks like it relies upon a C Extension Library for libxml2. IronPython doesn't support C Extension libraries - although there is an external project to get support for them in the form of IronClad (http://www.voidspace.org.uk/python/weblog/arch_d7_2008_02_16.shtml#e941). If you're referring to something else you'll need to be a little more concrete about what the folders look like. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Jose Ignacio Gisbert Sent: Monday, February 25, 2008 10:32 PM To: users at lists.ironpython.com Subject: [IronPython] How to import python folders as modules Hi all, IronPython Works well when you import python .py modules, but when you import python modules as folders (as xmpp), it does not recognize them. Someone knows how to do it? Thanks in advance, Best Regards, Ignacio -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Tue Feb 26 18:04:42 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Tue, 26 Feb 2008 09:04:42 -0800 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: <47C3FC49.3030500@zeomega.com> References: <47C3FC49.3030500@zeomega.com> Message-ID: <7AD436E4270DD54A94238001769C2227011CF570C279@DF-GRTDANE-MSG.exchange.corp.microsoft.com> What's MakeModule.py? Normally in v1.x if you do -X:SaveAssemblies or you use the pyc sample to compile a .py file you'll just be able to import it (like a .pyc file in Cpython). AddReference is used for normal .NET assemblies. But from the exception this looks like 2.0 - and I don't know how you're compiling in that case. It could be that MakeModule.py is working against an older version of the hosting APIs and needs to be updated. If you want more information about the exception I suggest running w/ -X:ExceptionDetail and we'll give you the full .NET stack trace. But as of now IronPython 2.0 doesn't support compiling to an assembly it's self although we're currently looking into doing that. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Suma Talya Sent: Tuesday, February 26, 2008 3:47 AM To: users at lists.ironpython.com Subject: Re: [IronPython] Exporting Python code as an assembly Hi, I have a py file by name IronPythonDLL.py containing --------------------------------------------------------------- import clr import System import sys from ClrWrapper import ClrAttribute, ClrAccepts, ClrReturns class IronPythonClass: clr_namespace = 'IronPythonDLL' @ClrReturns(System.String) def IPyMethod(self): return "IronPython Method" --------------------------------------------------------------- I have created IronPythonDLL.dll using MakeModule.py Now through ironpython interpreter i tried creating an instance of the above class and got an error, >>> import clr >>> clr.AddReference('IronPythonDLL.dll') >>> import IronPythonDLL >>> o=IronPythonDLL.IronPythonClass() Traceback (most recent call last): File IronPythonDLL, line unknown, in .ctor File IronPythonDLL, line unknown, in InitClass File , line unknown, in ##26 TypeError: Value cannot be null. Parameter name: scriptSource Any help on this will be useful.... Thanks, -Suma. _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From jigisbert.etra-id at grupoetra.com Tue Feb 26 19:50:49 2008 From: jigisbert.etra-id at grupoetra.com (j igisbert.etra-id) Date: Tue, 26 Feb 2008 19:50:49 +0100 Subject: [IronPython] How to import python folders as modules In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF570C276@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <000f01c87841$5b885d90$2a021fac@depid.local> <7AD436E4270DD54A94238001769C2227011CF570C276@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: Hi Dino, Thanks for your response, but I was not refering to pyxmpp. I am using xmpppy, http://xmpppy.sourceforge.net/ , and as long I have read, it does not contain any C Extension Library (or perhaps yes...). In normal Python it runs perfect, so it is no problem of the library itself. Yes, it contains an __ini__.py file, so that is because I do not understand why it does not work. Thanks again and I hope receive another answer. Best Regards, Ignacio -----Original Message----- From: Dino Viehland To: Discussion of IronPython Date: Tue, 26 Feb 2008 08:59:29 -0800 Subject: Re: [IronPython] How to import python folders as modules As long as there?s an __init__.py we should recognize it as a module. If by xmpp you?re referring to PyXMPP at http://pyxmpp.jajcus.net/ [http://pyxmpp.jajcus.net/] then it looks like it relies upon a C Extension Library for libxml2. IronPython doesn?t support C Extension libraries ? although there is an external project to get support for them in the form of IronClad (http://www.voidspace.org.uk/python/weblog/arch_d7_2008_02_16.shtml#e941 [http://www.voidspace.org.uk/python/weblog/arch_d7_2008_02_16.shtml#e941]). If you?re referring to something else you?ll need to be a little more concrete about what the folders look like. From:users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf OfJose Ignacio Gisbert Sent: Monday, February 25, 2008 10:32 PM To: users at lists.ironpython.com Subject: [IronPython] How to import python folders as modules Hi all, IronPython Works well when you import python .py modules, but when you import python modules as folders (as xmpp), it does not recognize them. Someone knows how to do it? Thanks in advance, Best Regards, Ignacio -------------- next part -------------- An HTML attachment was scrubbed... URL: From sanxiyn at gmail.com Tue Feb 26 20:15:41 2008 From: sanxiyn at gmail.com (Sanghyeon Seo) Date: Wed, 27 Feb 2008 04:15:41 +0900 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF570C279@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <47C3FC49.3030500@zeomega.com> <7AD436E4270DD54A94238001769C2227011CF570C279@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <5b0248170802261115t1441edb1j6b321c74d3a0a9b4@mail.gmail.com> 2008/2/27, Dino Viehland : > What's MakeModule.py? Curt Hagenlocher's work-in-progress tool which was discussed on this list. http://hagenlocher.org/software/ClrWrapper.zip -- Seo Sanghyeon From curt at hagenlocher.org Tue Feb 26 20:16:02 2008 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Tue, 26 Feb 2008 11:16:02 -0800 Subject: [IronPython] Exporting Python code as an assembly In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF570C279@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <47C3FC49.3030500@zeomega.com> <7AD436E4270DD54A94238001769C2227011CF570C279@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: On Tue, Feb 26, 2008 at 9:04 AM, Dino Viehland wrote: > What's MakeModule.py? That's from the project I started at http://www.codeplex.com/coils. Suma, you might consider getting a copy of the Codeplex tools and using them to download the most recent changes; I know I've fixed some things since the original version. Also, make sure you're using 2.0 Alpha 8 of IronPython. Unfortunately, I'm leaving on an email-less vacation in a few hours and don't have the time to offer any further assistance. I'll be back in three weeks and you can feel free to contact me then. -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From sjmachin at lexicon.net Wed Feb 27 00:12:23 2008 From: sjmachin at lexicon.net (John Machin) Date: Wed, 27 Feb 2008 10:12:23 +1100 Subject: [IronPython] How to import python folders as modules In-Reply-To: References: <000f01c87841$5b885d90$2a021fac@depid.local> <7AD436E4270DD54A94238001769C2227011CF570C276@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <47C49CD7.6060000@lexicon.net> j igisbert.etra-id wrote: > > Hi Dino, Thanks for your response, but I was not refering to pyxmpp. I > am using xmpppy, http://xmpppy.sourceforge.net/ , and as long I have > read, it does not contain any C Extension Library (or perhaps yes...). > In normal Python it runs perfect, so it is no problem of the library itself. > > Yes, it contains an __ini__.py file, so that is because I do not > understand why it does not work. > I hope you mean __init__.py, not __ini__.py Please give some concrete information, instead of "it does not recognize them" and "it does not work". (1) What is the full path .....\xmpppy\__init__.py ? (2) When you do import sys; print sys.path what do you see? In particular, does it include the answer to (1) ? (3) When you follow immediately with import xmpppy what exactly (copy/paste!) do you see? From jigisbert.etra-id at grupoetra.com Wed Feb 27 08:03:35 2008 From: jigisbert.etra-id at grupoetra.com (Jose Ignacio Gisbert) Date: Wed, 27 Feb 2008 08:03:35 +0100 Subject: [IronPython] How to import python folders as modules In-Reply-To: <47C49CD7.6060000@lexicon.net> References: <000f01c87841$5b885d90$2a021fac@depid.local> <7AD436E4270DD54A94238001769C2227011CF570C276@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47C49CD7.6060000@lexicon.net> Message-ID: <003001c8790e$df4233e0$2a021fac@depid.local> Ok, sorry guys for my lack of information. What I have is a folder called xmpp, with .py files including __init__.py In python2.5 I import it as normal module and it works perfectly, but in IronPython: What I do is to create a folder named "xmpp" under App_Script folder (so xmpp path it's no necessary I think), and after I attach xmpp files to it (including __init__.py). Then, I import module as I did in Python, "import xmpp", and what I receive is an error message with "No module named xmpp" I am sure I do not using well Ironpython (I am new here), so if you need more information please tell me. Thanks again and I am waiting for your response -----Mensaje original----- De: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] En nombre de John Machin Enviado el: mi?rcoles, 27 de febrero de 2008 0:12 Para: Discussion of IronPython Asunto: Re: [IronPython] How to import python folders as modules j igisbert.etra-id wrote: > > Hi Dino, Thanks for your response, but I was not refering to pyxmpp. I > am using xmpppy, http://xmpppy.sourceforge.net/ , and as long I have > read, it does not contain any C Extension Library (or perhaps yes...). > In normal Python it runs perfect, so it is no problem of the library itself. > > Yes, it contains an __ini__.py file, so that is because I do not > understand why it does not work. > I hope you mean __init__.py, not __ini__.py Please give some concrete information, instead of "it does not recognize them" and "it does not work". (1) What is the full path .....\xmpppy\__init__.py ? (2) When you do import sys; print sys.path what do you see? In particular, does it include the answer to (1) ? (3) When you follow immediately with import xmpppy what exactly (copy/paste!) do you see? _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From sanxiyn at gmail.com Wed Feb 27 10:11:55 2008 From: sanxiyn at gmail.com (Sanghyeon Seo) Date: Wed, 27 Feb 2008 18:11:55 +0900 Subject: [IronPython] How to import python folders as modules In-Reply-To: <003001c8790e$df4233e0$2a021fac@depid.local> References: <000f01c87841$5b885d90$2a021fac@depid.local> <7AD436E4270DD54A94238001769C2227011CF570C276@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47C49CD7.6060000@lexicon.net> <003001c8790e$df4233e0$2a021fac@depid.local> Message-ID: <5b0248170802270111j714c23cj59584b5f2d437097@mail.gmail.com> 2008/2/27, Jose Ignacio Gisbert : > What I do is to create a folder named "xmpp" under App_Script folder (so > xmpp path it's no necessary I think), and after I attach xmpp files to it > (including __init__.py). > > Then, I import module as I did in Python, "import xmpp", and what I receive > is an error message with "No module named xmpp" What is App_Script folder? -- Seo Sanghyeon From jigisbert.etra-id at grupoetra.com Wed Feb 27 10:19:48 2008 From: jigisbert.etra-id at grupoetra.com (Jose Ignacio Gisbert) Date: Wed, 27 Feb 2008 10:19:48 +0100 Subject: [IronPython] How to import python folders as modules In-Reply-To: <5b0248170802270111j714c23cj59584b5f2d437097@mail.gmail.com> References: <000f01c87841$5b885d90$2a021fac@depid.local><7AD436E4270DD54A94238001769C2227011CF570C276@DF-GRTDANE-MSG.exchange.corp.microsoft.com><47C49CD7.6060000@lexicon.net><003001c8790e$df4233e0$2a021fac@depid.local> <5b0248170802270111j714c23cj59584b5f2d437097@mail.gmail.com> Message-ID: <004e01c87921$e6fe3440$2a021fac@depid.local> What I undestand is that App_Script folder is like App_Data in C# but in IronPython, in Visual Studio. If I put there a .py python module, then from code I can import it as it was in the same folder. For example, if I put a file called bscw.py in App_Script, I can import it then by calling "import bscw.py". -----Mensaje original----- De: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] En nombre de Sanghyeon Seo Enviado el: mi?rcoles, 27 de febrero de 2008 10:12 Para: Discussion of IronPython Asunto: Re: [IronPython] How to import python folders as modules 2008/2/27, Jose Ignacio Gisbert : > What I do is to create a folder named "xmpp" under App_Script folder (so > xmpp path it's no necessary I think), and after I attach xmpp files to it > (including __init__.py). > > Then, I import module as I did in Python, "import xmpp", and what I receive > is an error message with "No module named xmpp" What is App_Script folder? -- Seo Sanghyeon _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From sjmachin at lexicon.net Wed Feb 27 11:07:18 2008 From: sjmachin at lexicon.net (John Machin) Date: Wed, 27 Feb 2008 21:07:18 +1100 Subject: [IronPython] How to import python folders as modules In-Reply-To: <003001c8790e$df4233e0$2a021fac@depid.local> References: <000f01c87841$5b885d90$2a021fac@depid.local> <7AD436E4270DD54A94238001769C2227011CF570C276@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <47C49CD7.6060000@lexicon.net> <003001c8790e$df4233e0$2a021fac@depid.local> Message-ID: <47C53656.9000506@lexicon.net> Jose Ignacio Gisbert wrote: > Ok, sorry guys for my lack of information. > > What I have is a folder called xmpp, with .py files including __init__.py In > python2.5 I import it as normal module and it works perfectly, but in > IronPython: > > What I do is to create a folder named "xmpp" under App_Script folder (so > xmpp path it's no necessary I think), If you know what is necessary and what's not, you wouldn't need to be asking questions here. Just answer the questions. > and after I attach xmpp files to it > (including __init__.py). > > Then, I import module as I did in Python, "import xmpp", and what I receive > is an error message with "No module named xmpp" > > I am sure I do not using well Ironpython (I am new here), so if you need > more information please tell me. > I already asked for some *precise* information: (1) What is the full path .....\xmpp\__init__.py ? (2) When you do import sys; print sys.path what do you see? In particular, does it include the answer to (1) ? If you tell us that, we might be able to tell you what is going wrong. From fuzzyman at voidspace.org.uk Wed Feb 27 12:18:04 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Wed, 27 Feb 2008 11:18:04 +0000 Subject: [IronPython] How to import python folders as modules In-Reply-To: <004e01c87921$e6fe3440$2a021fac@depid.local> References: <000f01c87841$5b885d90$2a021fac@depid.local><7AD436E4270DD54A94238001769C2227011CF570C276@DF-GRTDANE-MSG.exchange.corp.microsoft.com><47C49CD7.6060000@lexicon.net><003001c8790e$df4233e0$2a021fac@depid.local> <5b0248170802270111j714c23cj59584b5f2d437097@mail.gmail.com> <004e01c87921$e6fe3440$2a021fac@depid.local> Message-ID: <47C546EC.7050006@voidspace.org.uk> Jose Ignacio Gisbert wrote: > What I undestand is that App_Script folder is like App_Data in C# but in > IronPython, in Visual Studio. If I put there a .py python module, then from > code I can import it as it was in the same folder. For example, if I put a > file called bscw.py in App_Script, I can import it then by calling "import > bscw.py". > > There is a bug in the ASP.NET IronPython integration that prevents you from using packages (I believe). If this is where you are finding this problem then you will probably be better off asking questions on the IronPython for ASP.NET mailing list. Michael Foord http://www.manning.com/foord > -----Mensaje original----- > De: users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] En nombre de Sanghyeon Seo > Enviado el: mi?rcoles, 27 de febrero de 2008 10:12 > Para: Discussion of IronPython > Asunto: Re: [IronPython] How to import python folders as modules > > 2008/2/27, Jose Ignacio Gisbert : > >> What I do is to create a folder named "xmpp" under App_Script folder (so >> xmpp path it's no necessary I think), and after I attach xmpp files to it >> (including __init__.py). >> >> Then, I import module as I did in Python, "import xmpp", and what I >> > receive > >> is an error message with "No module named xmpp" >> > > What is App_Script folder? > > From jigisbert.etra-id at grupoetra.com Wed Feb 27 12:43:32 2008 From: jigisbert.etra-id at grupoetra.com (Jose Ignacio Gisbert) Date: Wed, 27 Feb 2008 12:43:32 +0100 Subject: [IronPython] How to import python folders as modules In-Reply-To: <47C546EC.7050006@voidspace.org.uk> References: <000f01c87841$5b885d90$2a021fac@depid.local><7AD436E4270DD54A94238001769C2227011CF570C276@DF-GRTDANE-MSG.exchange.corp.microsoft.com><47C49CD7.6060000@lexicon.net><003001c8790e$df4233e0$2a021fac@depid.local> <5b0248170802270111j714c23cj59584b5f2d437097@mail.gmail.com><004e01c87921$e6fe3440$2a021fac@depid.local> <47C546EC.7050006@voidspace.org.uk> Message-ID: <007101c87935$fb0fbf80$2a021fac@depid.local> Thanks Michael, because my intention is to use it with ASP.NET, building a web site. Thanks for the advice. Best regards. -----Mensaje original----- De: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] En nombre de Michael Foord Enviado el: mi?rcoles, 27 de febrero de 2008 12:18 Para: Discussion of IronPython Asunto: Re: [IronPython] How to import python folders as modules Jose Ignacio Gisbert wrote: > What I undestand is that App_Script folder is like App_Data in C# but in > IronPython, in Visual Studio. If I put there a .py python module, then from > code I can import it as it was in the same folder. For example, if I put a > file called bscw.py in App_Script, I can import it then by calling "import > bscw.py". > > There is a bug in the ASP.NET IronPython integration that prevents you from using packages (I believe). If this is where you are finding this problem then you will probably be better off asking questions on the IronPython for ASP.NET mailing list. Michael Foord http://www.manning.com/foord > -----Mensaje original----- > De: users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] En nombre de Sanghyeon Seo > Enviado el: mi?rcoles, 27 de febrero de 2008 10:12 > Para: Discussion of IronPython > Asunto: Re: [IronPython] How to import python folders as modules > > 2008/2/27, Jose Ignacio Gisbert : > >> What I do is to create a folder named "xmpp" under App_Script folder (so >> xmpp path it's no necessary I think), and after I attach xmpp files to it >> (including __init__.py). >> >> Then, I import module as I did in Python, "import xmpp", and what I >> > receive > >> is an error message with "No module named xmpp" >> > > What is App_Script folder? > > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From fuzzyman at voidspace.org.uk Thu Feb 28 23:03:40 2008 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Thu, 28 Feb 2008 22:03:40 +0000 Subject: [IronPython] Hashing in IronPython Message-ID: <47C72FBC.5070300@voidspace.org.uk> At Resolver Systems we are seeing IronPython use a radically lower amount of unique hashes for tuples - which we *believe* may be at the root of a performance problem with using dictionaries keyed by tuples. CPython 2.5 >>> hashes = set() >>> for i in range(1000): ... for j in range(1000): ... hashes.add(hash((i, j))) ... >>> len(hashes) 1000000 Same code on IronPython 2: IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.1433 Copyright (c) Microsoft Corporation. All rights reserved. >>> hashes = set() >>> for i in range(1000): ... for j in range(1000): ... hashes.add(hash((i, j))) ... >>> len(hashes) 32768 >>> We have a work around (using 2D arrays instead of dictionaries) but as dictionaries are heavily used in Python it is likely to be a problem for others as well. All the best, Michael Foord http://www.manning.com/foord From dinov at exchange.microsoft.com Fri Feb 29 02:15:10 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Thu, 28 Feb 2008 17:15:10 -0800 Subject: [IronPython] Hashing in IronPython In-Reply-To: <47C72FBC.5070300@voidspace.org.uk> References: <47C72FBC.5070300@voidspace.org.uk> Message-ID: <7AD436E4270DD54A94238001769C2227011CF570CA44@DF-GRTDANE-MSG.exchange.corp.microsoft.com> I'll fix this for the next release. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: Thursday, February 28, 2008 2:04 PM To: Discussion of IronPython Subject: [IronPython] Hashing in IronPython At Resolver Systems we are seeing IronPython use a radically lower amount of unique hashes for tuples - which we *believe* may be at the root of a performance problem with using dictionaries keyed by tuples. CPython 2.5 >>> hashes = set() >>> for i in range(1000): ... for j in range(1000): ... hashes.add(hash((i, j))) ... >>> len(hashes) 1000000 Same code on IronPython 2: IronPython 2.0 Alpha (2.0.0.800) on .NET 2.0.50727.1433 Copyright (c) Microsoft Corporation. All rights reserved. >>> hashes = set() >>> for i in range(1000): ... for j in range(1000): ... hashes.add(hash((i, j))) ... >>> len(hashes) 32768 >>> We have a work around (using 2D arrays instead of dictionaries) but as dictionaries are heavily used in Python it is likely to be a problem for others as well. All the best, Michael Foord http://www.manning.com/foord _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From myeates at jpl.nasa.gov Fri Feb 29 02:18:24 2008 From: myeates at jpl.nasa.gov (Mathew Yeates) Date: Thu, 28 Feb 2008 17:18:24 -0800 Subject: [IronPython] ipy 1.1.1crash at startup Message-ID: <47C75D60.7090307@jpl.nasa.gov> What the heck? ipy used to work fine but now I get An unhandled exception of type 'System.Security.SecurityException' occurred in mscorlib.dll Additional information: ECall methods must be packaged into a system module. I have .Net 2 and 3 installed. Mathew From dinov at exchange.microsoft.com Fri Feb 29 02:36:34 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Thu, 28 Feb 2008 17:36:34 -0800 Subject: [IronPython] ipy 1.1.1crash at startup In-Reply-To: <47C75D60.7090307@jpl.nasa.gov> References: <47C75D60.7090307@jpl.nasa.gov> Message-ID: <7AD436E4270DD54A94238001769C2227011CF570CA50@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Are you possibly running it off of a network share? .NET lowers the permissions for managed code when running from a network share. Are other managed apps running alright? -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Mathew Yeates Sent: Thursday, February 28, 2008 5:18 PM To: users at lists.ironpython.com Subject: [IronPython] ipy 1.1.1crash at startup What the heck? ipy used to work fine but now I get An unhandled exception of type 'System.Security.SecurityException' occurred in mscorlib.dll Additional information: ECall methods must be packaged into a system module. I have .Net 2 and 3 installed. Mathew _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From myeates at jpl.nasa.gov Fri Feb 29 02:47:03 2008 From: myeates at jpl.nasa.gov (Mathew Yeates) Date: Thu, 28 Feb 2008 17:47:03 -0800 Subject: [IronPython] ipy 1.1.1crash at startup In-Reply-To: <7AD436E4270DD54A94238001769C2227011CF570CA50@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <47C75D60.7090307@jpl.nasa.gov> <7AD436E4270DD54A94238001769C2227011CF570CA50@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <47C76417.8000100@jpl.nasa.gov> bizarre. I just and "repaired" my .Net 2 installation and now ipy is fine. I'm currently reinstalling the service packs and hopefully ipy will still work. Thanks Mathew Dino Viehland wrote: > Are you possibly running it off of a network share? .NET lowers the permissions for managed code when running from a network share. > > Are other managed apps running alright? > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Mathew Yeates > Sent: Thursday, February 28, 2008 5:18 PM > To: users at lists.ironpython.com > Subject: [IronPython] ipy 1.1.1crash at startup > > What the heck? ipy used to work fine but now I get > > An unhandled exception of type 'System.Security.SecurityException' > occurred in mscorlib.dll > > Additional information: ECall methods must be packaged into a system module. > > I have .Net 2 and 3 installed. > > Mathew > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From christopher.masters at credit-suisse.com Fri Feb 29 16:22:22 2008 From: christopher.masters at credit-suisse.com (Masters, Christopher) Date: Fri, 29 Feb 2008 10:22:22 -0500 Subject: [IronPython] Code generation questions Message-ID: <8C984B4799C04D4B8F80F746537145E11EA49B64@elon12p32001.csfp.co.uk> Hi Sorry if this is documented somewhere but can anyone help me with the following? If I (in 1.1.1) Execute() a string with code that defines some classes/defs methods, how long does the code generated last? For instance if I had the following script: class Foo: def __init__(self): # ... def DoWork(self): print "Doing work" def Run(): Foo().DoWork() And I hosted a runtime and executed this via: using (PythonEngine pe = new PythonEngine()) { IronPython.Runtime.Calls.Function0 run; pe.Execute(_pack[_pack.Properties["EntryPoint"]]); run = (IronPython.Runtime.Calls.Function0)pe.Globals["Run"]; run.Call(); } Is Run emitted as a DynamicMethod? What happens to Foo? Is it a generated as a CLR type? In which case does it hang around forever? What if I stored the Function0 reference and executed it later (after the PythonEngine is disposed)? Does the Foo type that Run instantiates still exist? Does anything related to this change in 2.0? Thanks Chris ============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html ============================================================================== From dinov at exchange.microsoft.com Fri Feb 29 19:44:24 2008 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Fri, 29 Feb 2008 10:44:24 -0800 Subject: [IronPython] Code generation questions In-Reply-To: <8C984B4799C04D4B8F80F746537145E11EA49B64@elon12p32001.csfp.co.uk> References: <8C984B4799C04D4B8F80F746537145E11EA49B64@elon12p32001.csfp.co.uk> Message-ID: <7AD436E4270DD54A94238001769C2227011CF570CB09@DF-GRTDANE-MSG.exchange.corp.microsoft.com> In the code you have below we should generate everything as collectible code. As long as you hold onto the delegate to Run you'll keep all of the code alive. Calling it after the engine is disposed will result in undefined behavior. And in this case Run will be generated as a dynamic method (as well as __init__ and DoWork). Run will have a reference to it's module (how it finds Foo) which is the reason why all of this will stay alive until you drop the reference to Run. Let me describe our general code collection strategy. There are two points where we will generate non-collectible code. The first is when you're inheriting from a .NET type such as: class foo(object): pass In this case we'll generate a subclass of object which overrides virtual methods and holds onto a python type object to track it's real type. We'll share the generated type between all types that inherit from object (adding __slots__ to a type definition causes more types to get generated). In your sample because you're using old-style classes no code is generated. The 2nd place where we generate uncollectible code is for modules. So if you have foo.py on disk and you do import foo we'll generate a type for the foo module. This is really just a performance optimization and can be turned off in both 1.0 and 2.0 (-X:GenerateAsSnippets command line option in 1.0 and most of 2.0, -X:TupleBasedOptimizedScopes in the latest 2.0 builds). This allows the modules to directly access static fields instead of having various values in dictionaries. If you're just sending some code off to a PythonEngine to be compiled though we'll use DynamicMethods. Those methods will be collected when the last reference to them goes away. 2.0 uses the same strategy here as 1.0 but when we compile modules in a collectibe way they run much faster than in 1.0. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Masters, Christopher Sent: Friday, February 29, 2008 7:22 AM To: 'users at lists.ironpython.com' Subject: [IronPython] Code generation questions Hi Sorry if this is documented somewhere but can anyone help me with the following? If I (in 1.1.1) Execute() a string with code that defines some classes/defs methods, how long does the code generated last? For instance if I had the following script: class Foo: def __init__(self): # ... def DoWork(self): print "Doing work" def Run(): Foo().DoWork() And I hosted a runtime and executed this via: using (PythonEngine pe = new PythonEngine()) { IronPython.Runtime.Calls.Function0 run; pe.Execute(_pack[_pack.Properties["EntryPoint"]]); run = (IronPython.Runtime.Calls.Function0)pe.Globals["Run"]; run.Call(); } Is Run emitted as a DynamicMethod? What happens to Foo? Is it a generated as a CLR type? In which case does it hang around forever? What if I stored the Function0 reference and executed it later (after the PythonEngine is disposed)? Does the Foo type that Run instantiates still exist? Does anything related to this change in 2.0? Thanks Chris ============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html ============================================================================== _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com