From 424141f44d1c971455d7d207ad386d1fcd7d854b Mon Sep 17 00:00:00 2001 From: Willian Padovani Germano Date: Wed, 2 Jul 2008 21:01:59 +0000 Subject: == Python, GE & Threads == Martin Sell (thanks!) reported that threading via scripts was not working in the game engine with Blender 2.46 and later. My fault, to make pynodes work properly with threads > 1 I disabled Python's "check interval", preventing threads created via scripts from receiving time to run. Now only during rendering check interval is disabled (set to max int). Still experimental, I added the calls in BPY_do_all_scripts, since it's called in BIF_do_render, but will probably move the code to its own function after more testing & feedback. --- source/blender/python/BPY_interface.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'source/blender/python') diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index 2f94e0eeebc..226657655fa 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -229,13 +229,6 @@ void BPY_start_python( int argc, char **argv ) /* Initialize thread support (also acquires lock) */ PyEval_InitThreads(); - /* Don't allow the Python Interpreter to release the GIL on - * its own, to guarantee PyNodes work properly. For Blender this - * is currently the best default behavior. - * The following code in C is equivalent in Python to: - * "import sys; sys.setcheckinterval(sys.maxint)" */ - _Py_CheckInterval = PyInt_GetMax(); - //Overrides __import__ init_ourImport( ); init_ourReload( ); @@ -2188,6 +2181,18 @@ void BPY_do_all_scripts( short event ) BPY_do_pyscript( &( G.scene->id ), event ); + /* Don't allow the Python Interpreter to release the GIL on + * its own, to guarantee PyNodes work properly. For Blender this + * is currently the best default behavior. + * The following code in C is equivalent in Python to: + * "import sys; sys.setcheckinterval(sys.maxint)" */ + if (event == SCRIPT_RENDER) { + _Py_CheckInterval = PyInt_GetMax(); + } + else if (event == SCRIPT_POSTRENDER) { + _Py_CheckInterval = 100; /* Python default */ + } + return; } @@ -2270,9 +2275,9 @@ void BPY_do_pyscript( ID * id, short event ) return; } - /* tell we're running a scriptlink. The sum also tells if this script - * is running nested inside another. Blender.Load needs this info to - * avoid trouble with invalid slink pointers. */ + /* tell we're running a scriptlink. The sum also tells if this + * script is running nested inside another. Blender.Load needs + * this info to avoid trouble with invalid slink pointers. */ during_slink++; disable_where_scriptlink( (short)during_slink ); -- cgit v1.2.3