与单音使用IronPython的奇怪的错误

在一些C#代码中运行IronPython 2.7.7有一个奇怪的情况。

我的目标是编写一个能够将数据写入Excel电子表格的Mac OS程序。 数据只能在一个C#库中打开的数据库中。

要导出电子表格,我有一个使用XLSXWriter的Python脚本,我通过IronPython从C#代码调用。

我从C#代码中调用了Python脚本,没有任何问题,脚本运行完美。 但是一旦脚本执行完毕,我在terminal中就会遇到一个SIGSEGV错误。 踢球者是电子表格打开完美。

这里是C#代码:

var engine = Python.CreateEngine(); var libPath = engine.GetSearchPaths(); libPath.Add(Environment.GetFolderPath(Environment.SpecialFolder.Personal + "/Downloads/IronPython-2.7.7/Lib"); engine.SetSearchPaths(libPath); var scope = engine.CreateScope(); engine.ExecuteFile(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/Downloads/ExcelScripts.py", scope); 

和我的Python脚本:

 import xlsxwriter import sys from os.path import expanduser home = expanduser("~") sys.path.append(home + "/.nuget/packages/ironpython/2.7.7/Lib") workbook = xlsxwriter.Workbook(home + "/Desktop/Output.xlsx") worksheet = workbook.add_worksheet() #Some simple example text worksheet.write('A1', 'Ticker') worksheet.write('B1', 'Company Name') worksheet.write('C1', 'Fiscal Year') worksheet.write('D1', 'Metric') workbook.close() 

最后,这里是我从terminal得到的输出:

 Stacktrace: at <unknown> <0xffffffff> at (wrapper managed-to-native) System.Delegate.CreateDelegate_internal (System.Type,object,System.Reflection.MethodInfo,bool) <0x00012> at System.Delegate.CreateDelegate (System.Type,object,System.Reflection.MethodInfo,bool,bool) [0x002f0] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/System/Delegate.cs:282 at System.Delegate.CreateDelegate (System.Type,object,System.Reflection.MethodInfo) [0x00000] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/System/Delegate.cs:292 at System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type,object) [0x0001a] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/System.Reflection.Emit/DynamicMethod.cs:189 at System.Linq.Expressions.Compiler.LambdaCompiler.CreateDelegate () [0x00000] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.cs:280 at System.Linq.Expressions.Compiler.LambdaCompiler.Compile (System.Linq.Expressions.LambdaExpression) [0x00013] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.cs:185 at System.Linq.Expressions.Expression`1<TDelegate_REF>.Compile (bool) [0x00000] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/LambdaExpression.cs:198 at System.Linq.Expressions.Expression`1<TDelegate_REF>.Compile () [0x00000] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/LambdaExpression.cs:181 at System.Runtime.CompilerServices.CallSiteBinder.BindCore<T_REF> (System.Runtime.CompilerServices.CallSite`1<T_REF>,object[]) [0x0003b] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/external/corefx/src/System.Linq.Expressions/src/System/Runtime/CompilerServices/CallSiteBinder.cs:144 at System.Dynamic.UpdateDelegates.UpdateAndExecute1<object, bool> (System.Runtime.CompilerServices.CallSite,object) [0x000ea] in /private/tmp/source-mono-2017-02/bockbuild-2017-02/profiles/mono-mac-xamarin/build-root/mono-x86/external/corefx/src/System.Linq.Expressions/src/System/Dynamic/UpdateDelegates.Generated.cs:258 at IronPython.Runtime.Binding.PythonConversionBinder.BoolConversion (System.Runtime.CompilerServices.CallSite,object) [0x00021] in <1304a224b80f47cdada4a1f932239862>:0 at IronPython.Runtime.Converter.ConvertToBoolean (object) [0x00010] in <1304a224b80f47cdada4a1f932239862>:0 at IronPython.Compiler.Ast.DynamicConvertExpression/BooleanConversionInstruction.Run (Microsoft.Scripting.Interpreter.InterpretedFrame) [0x00007] in <1304a224b80f47cdada4a1f932239862>:0 at Microsoft.Scripting.Interpreter.Interpreter.Run (Microsoft.Scripting.Interpreter.InterpretedFrame) [0x0001b] in <48823422b7404dddb2a834a9795980bd>:0 at Microsoft.Scripting.Interpreter.LightLambda.Run3<T0_REF, T1_REF, T2_REF, TRet_REF> (T0_REF,T1_REF,T2_REF) [0x00063] in <48823422b7404dddb2a834a9795980bd>:0 at Microsoft.Scripting.Interpreter.FuncCallInstruction`5<T0_REF, T1_REF, T2_REF, T3_REF, TRet_REF>.Run (Microsoft.Scripting.Interpreter.InterpretedFrame) [0x00064] in <48823422b7404dddb2a834a9795980bd>:0 at Microsoft.Scripting.Interpreter.Interpreter.Run (Microsoft.Scripting.Interpreter.InterpretedFrame) [0x0001b] in <48823422b7404dddb2a834a9795980bd>:0 at Microsoft.Scripting.Interpreter.LightLambda.Run4<T0_REF, T1_REF, T2_REF, T3_REF, TRet_REF> (T0_REF,T1_REF,T2_REF,T3_REF) [0x00074] in <48823422b7404dddb2a834a9795980bd>:0 at IronPython.Runtime.PythonContext.CallSplat (object,object[]) [0x0001f] in <1304a224b80f47cdada4a1f932239862>:0 at IronPython.Runtime.Operations.PythonCalls.Call (object,object[]) [0x00007] in <1304a224b80f47cdada4a1f932239862>:0 at IronPython.Runtime.WeakRefTracker.Finalize () [0x00060] in <1304a224b80f47cdada4a1f932239862>:0 at (wrapper runtime-invoke) object.runtime_invoke_virtual_void__this__ (object,intptr,intptr,intptr) [0x0001f] in <ffb99659fc1c47faa4d5f883014d08aa>:0 Native stacktrace: Debug info from gdb: (lldb) command source -s 0 '/tmp/mono-gdb-commands.747wYZ' Executing commands in '/tmp/mono-gdb-commands.747wYZ'. (lldb) process attach --pid 2809 Process 2809 stopped * thread #1, name = 'tid_403', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP frame #0: 0xa1651972 libsystem_kernel.dylib`semaphore_timedwait_trap + 10 libsystem_kernel.dylib`semaphore_timedwait_trap: -> 0xa1651972 <+10>: retl 0xa1651973 <+11>: nop libsystem_kernel.dylib`semaphore_timedwait_signal_trap: 0xa1651974 <+0>: movl $0xffffffd9, %eax ; imm = 0xFFFFFFD9 0xa1651979 <+5>: calll 0xa165b408 ; _sysenter_trap Executable module set to "/Library/Frameworks/Mono.framework/Versions/5.0.1/bin/mono32". Architecture set to: i386-apple-macosx. (lldb) thread list Process 2809 stopped * thread #1: tid = 0xbf1d, 0xa1651972 libsystem_kernel.dylib`semaphore_timedwait_trap + 10, name = 'tid_403', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP thread #2: tid = 0xbf1f, 0xa165930e libsystem_kernel.dylib`__psynch_cvwait + 10, name = 'SGen worker' thread #3: tid = 0xbf22, 0xa1659c4a libsystem_kernel.dylib`__wait4 + 10, name = 'Finalizer' thread #4: tid = 0xbf25, 0xa1659cba libsystem_kernel.dylib`__workq_kernreturn + 10 thread #5: tid = 0xbf26, 0xa165956a libsystem_kernel.dylib`__recvfrom + 10, name = 'Debugger agent' (lldb) thread backtrace all * thread #1, name = 'tid_403', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP * frame #0: 0xa1651972 libsystem_kernel.dylib`semaphore_timedwait_trap + 10 frame #1: 0x00255460 mono32`mono_coop_sem_timedwait [inlined] mono_os_sem_timedwait(timeout_ms=<unavailable>, flags=<unavailable>) at mono-os-semaphore.h:124 [opt] frame #2: 0x002553b6 mono32`mono_coop_sem_timedwait(sem=<unavailable>, timeout_ms=<unavailable>, flags=<unavailable>) at mono-coop-semaphore.h:54 [opt] frame #3: 0x00254f40 mono32`mono_domain_finalize(domain=<unavailable>, timeout=4294967295) at gc.c:513 [opt] frame #4: 0x00047856 mono32`mini_cleanup(domain=0x00254d7e) at mini-runtime.c:4105 [opt] frame #5: 0x000c4a65 mono32`mono_main(argc=<unavailable>, argv=<unavailable>) at driver.gc:2219 [opt] frame #6: 0x0003616b mono32`main [inlined] mono_main_with_options(argc=4, argc=4, argc=4, argv=0xbffcd8bc, argv=0xbffcd8bc, argv=0xbffcd8bc) at main.c:45 [opt] frame #7: 0x0003614a mono32`main(argc=4, argv=0xbffcd8bc) at main.c:338 [opt] frame #8: 0x00035985 mono32`start + 53 thread #2, name = 'SGen worker' frame #0: 0xa165930e libsystem_kernel.dylib`__psynch_cvwait + 10 frame #1: 0xa173deb0 libsystem_pthread.dylib`_pthread_cond_wait + 647 frame #2: 0xa173f844 libsystem_pthread.dylib`pthread_cond_wait$UNIX2003 + 51 frame #3: 0x002d6fb1 mono32`thread_func [inlined] mono_os_cond_wait(mutex=0x003ccc8c) at mono-os-mutex.h:146 [opt] frame #4: 0x002d6f9f mono32`thread_func(thread_data=0x00000000) at sgen-thread-pool.c:129 [opt] frame #5: 0xa173d047 libsystem_pthread.dylib`_pthread_body + 184 frame #6: 0xa173cf8f libsystem_pthread.dylib`_pthread_start + 243 frame #7: 0xa173c84a libsystem_pthread.dylib`thread_start + 34 thread #3, name = 'Finalizer' frame #0: 0xa1659c4a libsystem_kernel.dylib`__wait4 + 10 frame #1: 0xa15d82ef libsystem_c.dylib`waitpid$UNIX2003 + 32 frame #2: 0x00100b27 mono32`mono_handle_native_crash(signal=<unavailable>, ctx=0x00727fe0, info=0x00727fa0) at mini-exceptions.c:2567 [opt] frame #3: 0x0015d919 mono32`mono_arch_handle_altstack_exception(sigctx=<unavailable>, siginfo=<unavailable>, fault_addr=<unavailable>, stack_ovf=0) at exceptions-x86.c:1115 [opt] frame #4: 0x00042fc2 mono32`mono_sigsegv_signal_handler(_dummy=<unavailable>, _info=<unavailable>, context=<unavailable>) at mini-runtime.c:2860 [opt] frame #5: 0xa1733e5b libsystem_platform.dylib`_sigtramp + 43 frame #6: 0x001c0651 mono32`mono_method_signature_checked(m=0x00000000, error=0xb090e508) at loader.c:2352 [opt] frame #7: 0x001c3124 mono32`mono_method_signature(m=0x00000000) at loader.c:2501 [opt] frame #8: 0x001aca10 mono32`ves_icall_System_Delegate_CreateDelegate_internal(type=<unavailable>, target=0x00808168, info=0x00808168, throwOnBindFailure=<unavailable>) at icall.c:6166 [opt] frame #9: 0x02504e30 frame #10: 0x02504734 frame #11: 0x02513374 frame #12: 0x02d385e8 frame #13: 0x02d383e2 frame #14: 0x02d08098 frame #15: 0x02d07f80 frame #16: 0x02d07f18 frame #17: 0x02506260 frame #18: 0x02e1b174 frame #19: 0x02e1b54e frame #20: 0x02e1aae9 frame #21: 0x02e1aa1c frame #22: 0x025e1560 frame #23: 0x02e52fa4 frame #24: 0x02e4b171 frame #25: 0x025e1560 frame #26: 0x02d4cdd8 frame #27: 0x034b8a37 frame #28: 0x03d2c004 frame #29: 0x031a5b10 frame #30: 0x02ef7ac9 frame #31: 0x00254af6 mono32`mono_gc_run_finalize(obj=<unavailable>, data=<unavailable>) at gc.c:331 [opt] frame #32: 0x002921c9 mono32`sgen_client_run_finalize(obj=0x03110420) at sgen-mono.c:519 [opt] frame #33: 0x002a3200 mono32`sgen_gc_invoke_finalizers at sgen-gc.c:2523 [opt] frame #34: 0x00256a1c mono32`finalizer_thread [inlined] finalize_domain_objects at gc.c:868 [opt] frame #35: 0x002569ad mono32`finalizer_thread(unused=0x00000000) at gc.c:919 [opt] frame #36: 0x00226ce4 mono32`start_wrapper [inlined] start_wrapper_internal at threads.c:837 [opt] frame #37: 0x00226ba2 mono32`start_wrapper(data=<unavailable>) at threads.c:889 [opt] frame #38: 0x002edbf0 mono32`inner_start_thread(data=<unavailable>) at mono-threads.c:1170 [opt] frame #39: 0xa173d047 libsystem_pthread.dylib`_pthread_body + 184 frame #40: 0xa173cf8f libsystem_pthread.dylib`_pthread_start + 243 frame #41: 0xa173c84a libsystem_pthread.dylib`thread_start + 34 thread #4 frame #0: 0xa1659cba libsystem_kernel.dylib`__workq_kernreturn + 10 frame #1: 0xa173cd06 libsystem_pthread.dylib`_pthread_wqthread + 1210 frame #2: 0xa173c826 libsystem_pthread.dylib`start_wqthread + 34 thread #5, name = 'Debugger agent' frame #0: 0xa165956a libsystem_kernel.dylib`__recvfrom + 10 frame #1: 0xa15d84c6 libsystem_c.dylib`recv$UNIX2003 + 30 frame #2: 0x0013c058 mono32`socket_transport_recv(buf=<unavailable>, len=<unavailable>) at debugger-agent.c:1143 [opt] frame #3: 0x0012bb27 mono32`debugger_thread [inlined] transport_recv(len=11) at debugger-agent.c:1549 [opt] frame #4: 0x0012bb0b mono32`debugger_thread(arg=0x00000000) at debugger-agent.c:10157 [opt] frame #5: 0x002edbf0 mono32`inner_start_thread(data=<unavailable>) at mono-threads.c:1170 [opt] frame #6: 0xa173d047 libsystem_pthread.dylib`_pthread_body + 184 frame #7: 0xa173cf8f libsystem_pthread.dylib`_pthread_start + 243 frame #8: 0xa173c84a libsystem_pthread.dylib`thread_start + 34 (lldb) detach Process 2809 detached (lldb) quit ================================================================= Got a SIGSEGV while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your application. ================================================================= Abort trap: 6 

我已经自己运行了Python脚本,没有错误。 我唯一的猜测是,IronPython试图使用Mono有一些冲突。 我已经安装了VS for Mac(Xamarin.Mac和iOS)。 任何帮助,将不胜感激。

干杯