workaround for strange python problem in the BGE and BPy API where printing warnings mistook the blender binary for a script - argv[0], Binary lines were printed into the console sometimes causing console beeps and corrupting future console output.

Internal texts file on disk is not used it seems python warnings dont support this (even though exceptions do).

The most common cause of this is passing a float as an argument to a method that took an int.
get around this by setting __file__ in the namespace to the script name before executing the script, the file lines are not found but at least the output is not weird and confusing.

Added read only 'mode' attribute to the python controller so there is a way to tell if its executing a module or a script. Updated docs to better explain execution methods.
This commit is contained in:
2009-05-29 09:22:24 +00:00
parent 39177018af
commit edcb9f8863
3 changed files with 23 additions and 6 deletions

View File

@@ -2780,7 +2780,11 @@ static PyObject *RunPython( Text * text, PyObject * globaldict )
}
}
/* Without __file__ set the sys.argv[0] is used for the filename
* which ends up with lines from the blender binary being printed in the console */
PyDict_SetItemString(globaldict, "__file__", PyString_FromString(text->id.name+2));
return PyEval_EvalCode( text->compiled, globaldict, globaldict );
}