Random freezeing with uncapped framerate

Actually intervals are unnecessary to move. Surprisingly, the panda offers unpopular textbook solutions. Intervals have a problem, the time that the panda is trying to calculate to move is not constant for each frame. Object properties are also blocked, for example, you cannot control the Z axis. Use task manager for this purpose.

I changed the code:

from math import pi, sin, cos
 
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.actor.Actor import Actor
 
class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
 
        # Disable the camera trackball controls.
        self.disableMouse()
 
        # Load the environment model.
        self.scene = self.loader.loadModel("models/environment")
        # Reparent the model to render.
        self.scene.reparentTo(self.render)
        # Apply scale and position transforms on the model.
        self.scene.setScale(0.25, 0.25, 0.25)
        self.scene.setPos(-8, 42, 0)
 
        # Add the spinCameraTask procedure to the task manager.
        self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
        
        # Load and transform the panda actor.
        self.pandaActor = Actor("models/panda-model", {"walk": "models/panda-walk4"})
        self.pandaActor.setScale(0.005, 0.005, 0.005)
        self.pandaActor.setPos(0, 10, 0)
        self.pandaActor.reparentTo(self.render)
        # Loop its animation.
        self.pandaActor.loop("walk")
        
        # Run 1 interval
        self.taskMgr.add(self.pandaPosInterval1, "pandaPosInterval1")

        #Moving speed
        self.speed = 1
        #Rotational speed
        self.rotational = 50

    def pandaPosInterval1(self, task):
        if self.pandaActor.getY() <= -10:
            self.pandaActor.setY(-10)# Stop the increase in error over time.
            self.taskMgr.add(self.pandaRotation1, "pandaRotation1")
            return Task.done
        else:
            self.pandaActor.setY(self.pandaActor.getY()-self.speed*globalClock.getDt())
        return Task.cont

    def pandaRotation1(self, task):
        if self.pandaActor.getH() >= 180:
            self.pandaActor.setH(180)# Stop the increase in error over time.
            self.taskMgr.add(self.pandaPosInterval2, "pandaPosInterval2")
            return Task.done
        else:
            self.pandaActor.setH(self.pandaActor.getH()+self.rotational*globalClock.getDt())
        return Task.cont
        
    def pandaPosInterval2(self, task):
        if self.pandaActor.getY() >= 10:
            self.pandaActor.setY(10) # Stop the increase in error over time.
            self.taskMgr.add(self.pandaRotation2, "pandaRotation2")
            return Task.done
        else:
            self.pandaActor.setY(self.pandaActor.getY()+self.speed*globalClock.getDt())
        return Task.cont
        
    def pandaRotation2(self, task):
        if self.pandaActor.getH() <= 0:
            self.pandaActor.setH(0)# Stop the increase in error over time.
            self.taskMgr.add(self.pandaPosInterval1, "pandaPosInterval1")
            return Task.done
        else:
            self.pandaActor.setH(self.pandaActor.getH()-self.rotational*globalClock.getDt())
        return Task.cont

    # Define a procedure to move the camera.
    def spinCameraTask(self, task):
        angleDegrees = task.time * 6.0
        angleRadians = angleDegrees * (pi / 180.0)
        self.camera.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)
        self.camera.setHpr(angleDegrees, 0, 0)
        return Task.cont
 
app = MyApp()
app.run()