# How to proper run a python script and a physics simulation simultaneously?

I'm trying to animate objects via script and simultaneously run a physics simulation, but it's not working correctly. The physics simulation is several frames off:

The Setup is quite simple: I arranged my letters and added a rigid body to each of them. The z-location as well as the x- and y-rotation is locked.

I added an event handler with the following script to my scene, run it and played the animation:

import bpy
import random

def animate(scene):
random_object = objects[random.randrange(0, 15)]
random_object.scale *= 1.05

objects = bpy.data.collections["ABC"].objects

bpy.app.handlers.frame_change_post.append(animate)


I already tried to scale the object on every second frame, so that the physics could calculate after that, but that did not help.

In Blender 2.79 I get the same behaviour.

The script is just a test. Later on I want to parse a text and change the scale for the corresponding letters in the text.

Is there a way to run that simulation smoothly?