I thought I’d mention this, because it’s a relatively recent addition following the Hive patches submitted by Sjoerd de Vries.
The bpy API now provides handlers for pre-game and post-game execution in the embedded player (since 2.6 something).
These are very useful if you are writing an addon or a helper script which requires data that doesn’t exist in the Blender Game Engine, or for pre-computing complex problems. You should use these in combination with the save and load callbacks to ensure that this works for the external player to.
One example is: Writing a callback which reads all Curve objects, stores the bezier information to a file, then reads this in the Blender Game Engine and uses drawLine to draw the bezier.
Check out bpy.app.handlers on the documentation website.