Fix T38541: sys.exit fails when blender is built as a py-module
authorCampbell Barton <ideasman42@gmail.com>
Wed, 12 Feb 2014 19:53:42 +0000 (06:53 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 12 Feb 2014 19:58:06 +0000 (06:58 +1100)
source/blender/python/intern/bpy_interface.c
source/blender/windowmanager/intern/wm_init_exit.c
source/creator/creator.c

index aafb5e3d6422681f78f6abdc570efbb580805732..a547604cdd6f6d7e48841fa917ccf74e221b91c4 100644 (file)
@@ -361,8 +361,10 @@ void BPY_python_start(int argc, const char **argv)
 void BPY_python_end(void)
 {
        // fprintf(stderr, "Ending Python!\n");
 void BPY_python_end(void)
 {
        // fprintf(stderr, "Ending Python!\n");
+       PyGILState_STATE gilstate;
 
 
-       PyGILState_Ensure(); /* finalizing, no need to grab the state */
+       /* finalizing, no need to grab the state, except when we are a module */
+       gilstate = PyGILState_Ensure();
        
        /* free other python data. */
        pyrna_free_types();
        
        /* free other python data. */
        pyrna_free_types();
@@ -373,10 +375,12 @@ void BPY_python_end(void)
 
 #ifndef WITH_PYTHON_MODULE
        BPY_atexit_unregister(); /* without this we get recursive calls to WM_exit */
 
 #ifndef WITH_PYTHON_MODULE
        BPY_atexit_unregister(); /* without this we get recursive calls to WM_exit */
-#endif
 
        Py_Finalize();
 
        Py_Finalize();
-       
+#else
+       PyGILState_Release(gilstate);
+#endif
+
 #ifdef TIME_PY_RUN
        /* measure time since py started */
        bpy_timer = PIL_check_seconds_timer() - bpy_timer;
 #ifdef TIME_PY_RUN
        /* measure time since py started */
        bpy_timer = PIL_check_seconds_timer() - bpy_timer;
index e0ec9c994db97ad930fda1cb76653f3f3cde3a43..5b1fd90a0df5569418b64731ae67f4d0cfd36cb8 100644 (file)
@@ -522,20 +522,21 @@ void WM_exit_ext(bContext *C, const bool do_python)
                MEM_printmemlist();
        }
        wm_autosave_delete();
                MEM_printmemlist();
        }
        wm_autosave_delete();
-       
+}
+
+void WM_exit(bContext *C)
+{
+       WM_exit_ext(C, 1);
+
        printf("\nBlender quit\n");
        printf("\nBlender quit\n");
-       
-#ifdef WIN32   
+
+#ifdef WIN32
        /* ask user to press a key when in debug mode */
        if (G.debug & G_DEBUG) {
                printf("Press any key to exit . . .\n\n");
                wait_for_console_key();
        }
        /* ask user to press a key when in debug mode */
        if (G.debug & G_DEBUG) {
                printf("Press any key to exit . . .\n\n");
                wait_for_console_key();
        }
-#endif 
-}
+#endif
 
 
-void WM_exit(bContext *C)
-{
-       WM_exit_ext(C, 1);
        exit(G.is_break == TRUE);
 }
        exit(G.is_break == TRUE);
 }
index 8fdd19e007a67380df3cf1b4e07ebc0f0720a4b8..dbb7bef972352e1efcb7381fb43b748b43c4bd40 100644 (file)
@@ -1746,7 +1746,7 @@ int main(int argc, const char **argv)
 #ifdef WITH_PYTHON_MODULE
 void main_python_exit(void)
 {
 #ifdef WITH_PYTHON_MODULE
 void main_python_exit(void)
 {
-       WM_exit((bContext *)evil_C);
+       WM_exit_ext((bContext *)evil_C, true);
        evil_C = NULL;
 }
 #endif
        evil_C = NULL;
 }
 #endif