python termination error when ctypes dll calls printf
Question: I am developing a python system with some core dlls accessed via ctypes. I
have reduced the problem to this condition: execute a module that loads (no
need to call) two dlls, one of which calls printf -- this error will occur in
exit.

> This application has requested the Runtime to terminate it in an unusual
> way. Please contact the application's support team for more information.

My environment:  
\- Windows 7, SP1 \- Python 2.7.8 \- MinGW v 3.20

This test case is adapted from a tutorial on writing dlls with MinGW:

    
    
    /* add_core.c */
    __declspec(dllexport) int sum(int a, int b) {
        return a + b;
    }
    
    /* sub_core.c */
    #include <stdio.h>
    __declspec(dllexport) int sum(int a, int b) {
        printf("Hello from sub_core.c");
        return a - b;
    }
    

prog.py

    
    
    import ctypes
    add_core_dll = ctypes.cdll.LoadLibrary('add_core.dll')
    add_core_dll = ctypes.cdll.LoadLibrary('sub_core.dll')
    
    
    
    > make
    gcc -Wall -O3 -g -ansi -c  add_core.c -o add_core.o
    gcc -g -L. -ansi             -shared add_core.o -o add_core.dll
    gcc -Wall -O3 -g -ansi -c  sub_core.c -o sub_core.o
    gcc -g -L. -ansi             -shared sub_core.o -o sub_core.dll
    
    >python prog.py
    
    This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information.
    

and pops up a message dialog to the same effect: "python.exe has stopped
working ...".

Note that the programs execute as expected and produce normal output. This
error at termination is just a big nuisance I'd like to be rid of.


Answer: the same happens for: Windows 7 Enterprise, SP1 Python 2.7.11 mingw32-g++.exe
5.3.0

