[Python.NET] installation on GNU/Linux
Hi all, I have installed pythonnet and thought it would be of interest to send the outputs of the tests included in the library. -- Jean Pierre configuration - Debian GNU/Linux 3.1 kernel 2.6 python-2.4.2 mono-1.1.13.4 pythonnet-1.0-rc2-py2.4-clr1.1 axtom:/opt/pythonnet# mono python.exe Python 2.4.2 (#2, Apr 1 2006, 11:19:10) [GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path.append('/opt/pythonnet/src/tests') >>> import runtests >>> runtests.main() ..F. test_exceptions == FAIL: Test the str() representation of an exception. -- Traceback (most recent call last): File "/opt/pythonnet/src/tests/test_exceptions.py", line 310, in testStrOfException self.failUnless(str(e).find('at System.DateTime.Parse') > -1) AssertionError -- Ran 20 tests in 0.271s FAILED (failures=1) ...F test_module == FAIL: Test implicit assembly loading via import. -- Traceback (most recent call last): File "/opt/pythonnet/src/tests/test_module.py", line 177, in testImplicitAssemblyLoad self.failUnlessRaises(ImportError, test) AssertionError: ImportError not raised -- Ran 20 tests in 0.127s FAILED (failures=1) test_conversion -- Ran 20 tests in 0.054s OK ... test_class -- Ran 15 tests in 0.017s OK test_interface -- Ran 4 tests in 0.003s OK .E. test_enum == ERROR: Test enumeration conversion with FlagsAttribute set. -- Traceback (most recent call last): File "/opt/pythonnet/src/tests/test_enum.py", line 130, in testEnumWithFlagsAttrConversion label = Label() NullReferenceException: Object reference not set to an instance of an object in <0x00013> System.Windows.Forms.Label:get_DefaultSize () in <0x001b3> System.Windows.Forms.Control:.ctor () in <0x0001b> System.Windows.Forms.Label:.ctor () in <0x0> in (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (object,object[]) in <0x0008d> System.Reflection.MonoCMethod:Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) -- Ran 15 tests in 0.099s FAILED (errors=1) .. test_field -- Ran 30 tests in 0.005s OK .. test_property -- Ran 10 tests in 0.004s OK test_indexer -- Ran 28 tests in 0.100s OK Mono System.Windows.Forms Assembly [Revision: 54007; built: 2005/12/6 14:35:24] E... test_event == ERROR: Test remove on an event sink implemented w/internalcall. -- Traceback (most recent call last): File "/opt/pythonnet/src/tests/test_event.py", line 505, in testRemoveInternalCallHandler f = Form() TypeInitializationException: An exception was thrown by the type initializer for System.Windows.Forms.XplatUI in <0x0> in <0x00064> System.Windows.Forms.Form:get_CreateParams () in <0x00273> System.Windows.Forms.Control:.ctor () in <0x00011> System.Windows.Forms.ScrollableControl:.ctor () in <0x00010> System.Windows.Forms.ContainerControl:.ctor () in <0x00019> System.Windows.Forms.Form:.ctor () in <0x0> in (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (object,object[]) in <0x0008d> System.Reflection.MonoCMethod:Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) --
[Python.NET] [PythonNet] 2/ 2 Resolve "Float ValueError in different regional settings (Windows XP)"
Issue #2 Update (Resolve) "Float ValueError in different regional settings (Windows XP)" Status Resolved, Testing/bug medium To followup, visit: http://zope.org/Members/Brian/PythonNet/Collector/2 == = Resolve - Entry #2 by Brian on Jan 17, 2005 4:01 pm Status: Pending => Resolved This is fixed for the next release. Thanks for the report! --Brian = Request - Entry #1 by Anonymous User on Dec 15, 2004 2:51 am started runtests.py some test fail with a message like: ERROR: Test single fields. -- Traceback (most recent call last): File "D:\Downloads\python\PythonNet-1.0-beta4\PythonNet-1.0-beta4\tests\python \test_field.py", line 363, in testSingleField self.failUnless(object.SingleField == 1.1) ValueError: invalid literal for float(): 1,1 The regional settings (German): decimal symbol: , digit grouping symbol: . == _ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
[Python.NET] [PythonNet] 6/ 2 Resolve "Hang caused by multithreaded program that invokes .NET CLR"
Issue #6 Update (Resolve) "Hang caused by multithreaded program that invokes .NET CLR" Status Resolved, Threading/bug critical To followup, visit: http://www.zope.org/Members/Brian/PythonNet/Collector/6 == = Resolve - Entry #2 by Brian on Mar 31, 2005 9:54 am Status: Pending => Resolved This issue is resolved in beta 5 - thanks for the test case (I put a condensed version of it into the unit tests). -BL = Request - Entry #1 by Anonymous User on Mar 25, 2005 1:04 pm Hang caused by multithreaded program accessing CLR methods. I successfully reproduced the state with a very simple application. Here is very dumb python program that uses the CLR: from CLR.System import String class cSharpCaller( object ): def __init__( self ): print "Created a cSharpCaller instance" self.__cSharpString = None def createCSharpString( self, str ): self.__cSharpString = String( str ) def returnCSharpString( self ): return self.__cSharpString.ToString() And if I test this with this (dumb) threethreaded testprogram: import threading, thread, time from cSharpCaller import cSharpCaller def start_threads(amount=5): for i in range(amount): thread = threading.Thread(target=process_thread ) print "starting thread ", thread.getName() thread.start() def process_thread( ): print "thread started " for i in range( 2 ): print "Hi, I'm a thread" time.sleep( 1 ) cs = cSharpCaller( ) cs.createCSharpString( "created from a thread" ) print "cs.returnCSharpString() = ", cs.returnCSharpString() print "thread %s ended" start_threads( 3 ) I get this output: starting thread thread0 thread started Hi, I'm thread %s starting thread thread1 thread started Hi, I'm thread %s starting thread thread2 thread started Hi, I'm thread %s Hi, I'm thread %s Hi, I'm thread %s Hi, I'm thread %s Created a cSharpCaller instance Created a cSharpCaller instance cs.returnCSharpString() = and I have to CTRL+Pause to get out of the hang. Clearly hangs on the first String.ToString() method call. == _ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
[Python.NET] [PythonNet] 8/ 4 Resolve "Reentrancy bug"
Issue #8 Update (Resolve) "Reentrancy bug" Status Resolved, General/bug medium To followup, visit: http://www.zope.org/Members/Brian/PythonNet/Collector/8 == = Resolve - Entry #4 by Brian on Mar 31, 2005 1:21 pm Status: Pending => Resolved Great - thanks for the followup. I'm going to work on a 'tutorial for embedders' for the next release, as this isn't nearly well-documented enough... -BL = Comment - Entry #3 by Anonymous User on Mar 31, 2005 12:59 pm You're right -- the bug is indeed caused by the lack of a lock acquisition in that code. Thanks for the tip. This item should be closed. > = Comment - Entry #2 by Brian on Mar 31, 2005 9:45 am > > Note that to be thread-safe and reentrancy-safe you > also need to make sure that any managed code you have > that uses Python.Runtime objects or methods is acquiring > the Python lock first. For example: > > public class Example { > > public static int MethodThatCallsPython() { > // have to acquire the GIL to safely call back into > // Python!! > IntPtr state = PythonEngine.AcquireLock(); > > PythonEngine.RunSimpleString("print 'hello'"); > > // done using python for now, so release the GIL... > PythonEngine.ReleaseLock(state); > } > > } > > Forgetting to manage the lock around a callback into Python > is almost certain to cause a NullReferenceException (because > there will be no valid thread state when the callback is > made). > > ____ > = Request - Entry #1 by Anonymous User on Mar 30, 2005 8:10 pm > > There is a reentrancy problem when calling CLR code from Python that > calls back into Python. The sequence I use to reproduce the problem is > fairly simple: > 1) Execute some Python code either through PyObject.InvokeMethod, or > PythonEngine.RunSimpleString. > 2) From the executed Python code, call into a CLR class. > 3) From the CLR class, execute Python code again. > > Here is some example code that demonstrates the issue: > using System; > using Python.Runtime; > > namespace PDNBug { > public class Example { > [STAThread] > static void Main(string[] args) { > PythonEngine.Initialize(); > PythonEngine.RunSimpleString("from CLR.PDNBug import > Example\nExample.FirstCall()"); > } > > public static void FirstCall () { > Console.WriteLine("First call succeeded."); > PythonEngine.RunSimpleString("from CLR.PDNBug import > Example\nExample.SecondCall()"); > } > > public static void SecondCall () { > Console.WriteLine("Second call succeeded."); > } > } > } > > The output generated is: > First call succeeded. > Traceback (most recent call last): > File "", line 2, in ? > System.NullReferenceException: Object reference not set to an instance of > an object. >at Python.Runtime.Runtime.PyRun_SimpleString(String code) >at Python.Runtime.PythonEngine.RunSimpleString(String code) >at PDNBug.Example.FirstCall() in example.cs:line 15: Object reference > not set to an instance of an object. > > The expected output is: > First call succeeded. > Second call succeeded. > > This issue was previously posted to the mailing list > (http://mail.python.org/pipermail/pythondotnet/2005-January/000235.html). = Comment - Entry #2 by Brian on Mar 31, 2005 9:45 am Note that to be thread-safe and reentrancy-safe you also need to make sure that any managed code you have that uses Python.Runtime objects or methods is acquiring the Python lock first. For example: public class Example { public static int MethodThatCallsPython() { // have to acquire the GIL to safely call back into // Python!! IntPtr state = PythonEngine.AcquireLock(); PythonEngine.RunSimpleString("print 'hello'"); // done using python for now, so release the GIL... PythonEngine.ReleaseLock(state); } } Forgetting to manage the lock around a callback into Python is almost certain to cause a NullReferenceException (because there will be no valid thread state when the callback is made). ________ = Request - Entry #1 by Anonymous User on Mar 30, 2005 8:10 pm There is a reentrancy problem when calling CLR code from Python that calls back into Python. The sequen
[Python.NET] [PythonNet] 3/ 3 Resolve "Python strings should convert to byte[]"
Issue #3 Update (Resolve) "Python strings should convert to byte[]" Status Resolved, General/bug medium To followup, visit: http://www.zope.org/Members/Brian/PythonNet/Collector/3 == = Resolve - Entry #3 by Brian on Mar 31, 2005 10:16 pm Status: Accepted => Resolved oops - meant to resolve = Comment - Entry #2 by Brian on Mar 31, 2005 10:06 pm done for beta 6. -BL = Request - Entry #1 by Brian on Feb 8, 2005 10:55 am Status: Pending => Accepted Supporters added: Brian It should be possible to convert a string or sequence of single-character strings to a byte array. Not sure if its too DWIM-my to do the same for unicode strings... == _ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
[Python.NET] [PythonNet] 5/ 2 Resolve "Strange errors"
Issue #5 Update (Resolve) "Strange errors" Status Resolved, General/bug medium To followup, visit: http://www.zope.org/Members/Brian/PythonNet/Collector/5 == = Resolve - Entry #2 by Brian on Mar 31, 2005 10:19 pm Status: Pending => Resolved This is fixed for b6 - due to an ill-advised decref of globals that only happens when the CLR module is imported into an existing Python interpreter... -BL = Request - Entry #1 by Anonymous User on Mar 1, 2005 5:35 pm There seems to be some sort of strange crash occurring when importing CLR in the interactive prompt. It doesn't occur when executing a script from a file or in shells like PyCrust. Also, it does not happen at all in Python 2.3/PythonNET beta 3. Importing CLR seems to wreak havoc with the interpreter: Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import CLR >>> print dir() Traceback (most recent call last): File "", line 1, in ? NameError: name 'dir' is not defined >>> print dir(__import__) Traceback (most recent call last): File "", line 1, in ? NameError: name 'dir' is not defined >>> print __import__ Traceback (most recent call last): File "", line 1, in ? NameError: name '__import__' is not defined >>> __import__ Fatal Python error: GC object already tracked This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Keeping a reference to globals() seems to suppress it: D:\Python24>python.exe Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> a=globals() >>> import CLR >>> dir() ['CLR', '__builtins__', '__doc__', '__name__', 'a'] >>> __import__ == _ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
[Python.NET] [PythonNet] 1/ 2 Resolve "Invalid free()s (probably GC-related)"
Issue #1 Update (Resolve) "Invalid free()s (probably GC-related)" Status Resolved, General/bug medium To followup, visit: http://www.zope.org/Members/Brian/PythonNet/Collector/1 == = Resolve - Entry #2 by Brian on May 7, 2005 5:20 pm Status: Pending => Resolved Figured this out: interop was trying to release the char * for strings returned from python ;( = Request - Entry #1 by Brian on Dec 6, 2004 5:19 pm > Python For .NET beta 3 runs fine for me with Mono > version 1.01 on Linux. I do get "free(): invalid pointer" > messages, presumably from garbage collection (??) > but it does seem to run fine. > > James Phillips Thats great news ;) It also confirms that there is still a bug lurking somewhere in my interop-level memory mgmt (I've gotten reports of invalid frees under a debugger on win32 as well...) == _ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
[Python.NET] [PythonNet] 10/ 2 Resolve "Problem converting arrays"
Issue #10 Update (Resolve) "Problem converting arrays" Status Resolved, General/bug medium To followup, visit: http://www.zope.org/Members/Brian/PythonNet/Collector/10 == = Resolve - Entry #2 by Brian on May 7, 2005 5:27 pm Status: Pending => Resolved This is implemented for rc1. -BL = Request - Entry #1 by Anonymous User on Apr 12, 2005 3:37 pm Uploaded: "convert-sequences.patch" - http://www.zope.org/Members/Brian/PythonNet/Collector/10/convert-sequences.patch/view There's no generic conversion to object for Python arrays, so something like: > from CLR.System import Console > Console.WriteLine("{0}", [[1]]) will fail. Fix: convert to object[]. == _ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
[Python.NET] [PythonNet] 4/ 2 Resolve "Need better way to inspect PythonException"
Issue #4 Update (Resolve) "Need better way to inspect PythonException" Status Resolved, General/bug medium To followup, visit: http://www.zope.org/Members/Brian/PythonNet/Collector/4 == = Resolve - Entry #2 by Brian on May 7, 2005 5:24 pm Status: Pending => Resolved Type and Value should solve this... -BL = Request - Entry #1 by Brian on Feb 8, 2005 11:06 am >From managed code. == _ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
[Python.NET] [PythonNet] 9/ 2 Resolve "TypeError when parameters added to derived constructor"
Issue #9 Update (Resolve) "TypeError when parameters added to derived constructor" Status Resolved, General/bug medium To followup, visit: http://www.zope.org/Members/Brian/PythonNet/Collector/9 == = Resolve - Entry #2 by Brian on May 7, 2005 6:42 pm Status: Pending => Resolved Fixed for rc1. -BL = Request - Entry #1 by Anonymous User on Mar 31, 2005 6:38 pm Uploaded: "bug1.py" - http://www.zope.org/Members/Brian/PythonNet/Collector/9/bug1.py/view A TypeError is thrown when trying to derive a Python class from a .NET class when the Python class constructor has parameters beyond "self". == _ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
[Python.NET] [PythonNet] 7/ 4 Resolve "crash caused by interaction between pythondotnet and CLR."
Issue #7 Update (Resolve) "crash caused by interaction between pythondotnet and CLR." Status Resolved, Threading/bug critical To followup, visit: http://www.zope.org/Members/Brian/PythonNet/Collector/7 == = Resolve - Entry #4 by Brian on May 7, 2005 6:43 pm Status: Pending => Resolved Fixed for rc1. -BL = Comment - Entry #3 by Anonymous User on Mar 31, 2005 2:43 am hello, I have skimmed the test case, and removed all dependancies toward the Simpy framework. Now it crashes once the python main loop is finished. If I comment out the code used to pass a python function as a delegate to the C# frame, it doesn't. here is the code: #test to show problem. import sys,time sys.path.append('.') from CLR.System.Reflection import Assembly a = Assembly.LoadWithPartialName("testpython") from CLR.testpython import MainForm, TestDelegate def test(): return "hop" if __name__ == '__main__': form = MainForm.GetInstance() form.TestDelegateProperty = TestDelegate(test) form.Start() time.sleep(1) print "done" Stan. the CLR sources are the same. Contact me if any more info is needed. = Comment - Entry #2 by Anonymous User on Mar 30, 2005 11:18 am the python script to run is bin\Debug\test.py = Request - Entry #1 by Anonymous User on Mar 30, 2005 11:18 am Uploaded: "testpython.zip" - http://www.zope.org/Members/Brian/PythonNet/Collector/7/testpython.zip/view hello, the following application (python/C#) is working properly, when I do not run simpy, a python framework. Once I enable, I get an immediate crash. See enclosed for runnable/compilable example. (run "python test.py"). To run, it needs the Simpy framework, GPL, that you can get there: http://simpy.sourceforge.net/ Simpy makes heavy uses of the "yield" construct. as soon as I uncomment that line in the script: #simulate() I get an immediate crash. I see no reason for this crash. Stan. == _ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet
[Python.NET] [PythonNet] 16/ 2 Resolve "pythonw"
Issue #16 Update (Resolve) "pythonw" Status Resolved, General/bug medium To followup, visit: http://www.zope.org/Members/Brian/PythonNet/Collector/16 == = Resolve - Entry #2 by Brian on Oct 22, 2005 2:49 pm Status: Pending => Resolved I've added this for the next release. -BL = Request - Entry #1 by Anonymous User on Jul 26, 2005 10:13 pm When running pythonnet on windows, it always comes up with a black box. I reckon that this is a bug as it is not (always) desired. Stock python provides a program "pythonw" to turn this off. I request something similar to be done for this. (Alternatively, perhaps pythonnet could be packaged as a python module of sorts, so that I could use this in stock python?) Please email me re any updates: thestar at fussycoder dot id dot au == _ Python.NET mailing list - PythonDotNet@python.org http://mail.python.org/mailman/listinfo/pythondotnet