How to stop blender game engine using Python upon reaching a condition in the script?
It's very simple, you just have to connect a Game Actuator to your script Controller and set it to "Quit Game".

Add this actuator to your script by doing this:

gameactu = cont.actuators['Game']

if posdiff &lt; 0.0001: # You can also try 0.0002
    cont.activate(gameactu) # I just try it works.


Here a picture:



You can do this without the Actuator, see the manual.