Skip to content

Pythonnet crashes .Net application on exit. #245

Description

@dmitriyse

If we embed Python.Net into DotNet application, it crashes on Linux.
Crash occurs when application exits.

PythonEngine.Initialize();

try
{
    using (Py.GIL())
    {
        dynamic sysModule = Py.Import("sys");
        Console.WriteLine("Python engine version:");
        Console.WriteLine(sysModule.version);
    }

    // This workaround reduces risk of Mono crash.
    // Problem will be fixed in mono 4.6
    if (Type.GetType("Mono.Runtime") != null)
    {
        Runtime.Py_Main(3, new[] { "/pcfgtest.exe", "-c", "exit" });
    }
    else
    {
        // Program will crash if we will try to do this under Windows.
        //// Runtime.Py_Main(3, new[] { "/pcfgtest.exe", "-c", "exit" });
    }
}
finally
{
    PythonEngine.Shutdown();
}

This is sample of code that produces crash.
Also it contains 'probably workaround".

Console output :

tux@pythonnet:/mnt/Projects/pythonnet/2/src/configtest/bin/Release$ mono pcfgtest.exe
Starting application...
Python.runtime.dll substituted by Python.Runtime-Py35-Linux64.dll.
Python engine version:
3.5.2 (default, Jul  5 2016, 12:43:10)
[GCC 5.4.0 20160609]
Shutting down finalizer thread timed out.
* Assertion at gc.c:867, condition `finalizer_thread_exited' not met

Stacktrace:


Native stacktrace:

        mono() [0x4a77ca]
        /lib/x86_64-linux-gnu/libpthread.so.0(+0x113d0) [0x7f48084463d0]
        /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x38) [0x7f4807e8b418]
        /lib/x86_64-linux-gnu/libc.so.6(abort+0x16a) [0x7f4807e8d01a]
        mono() [0x6408c9]
        mono() [0x640ad7]
        mono() [0x640c26]
        mono() [0x5aee5e]
        mono(mono_runtime_cleanup+0xe) [0x5a85de]
        mono() [0x423cf7]
        mono(mono_main+0x10d7) [0x47a087]
        mono() [0x421818]
        /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f4807e76830]
        mono() [0x421c11]

Debug info from gdb:


=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================

Aborted (core dumped)

I tried everything - python 2.7, python 3.5, Mono 4.2, 4.4.
It does not matter, behavior always the same.

Also i tried to build with Py_DEBUG under linux (and pass python library from python3.5-dbg package)
I receive assertions on PythonEngine.Init:

  1. Decref -1 Assertions
  2. td_type != NULL Assertion

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions