A better way to check the linear velocity of it was zero would be to use:
if object.getVelocity().length == 0:
I’m afraid I don’t know a proper way. But you can make sure that it isn’t going to sleep by checking the ‘no sleep’ option in the physics panel, and you can force it either way by using enable and disable dynamics.
I would use care when comparing floating point values with “==”. Floating point math is no exact and there are numbers that cannot be directly represented. With floats it is usually a good idea to see if your value is “really close” to your target value instead of directly equal.
if math.fabs(object.getVelocity().length) < 0.001: