Hot to make a py defintion loop forever?

All the classic styles like:

while 1==1:

(which should work, but it crashes panda)
Don’t work! I tried intervals, tasks, just everything I could, but IT JUST DOES NOT WORK.(When I was writing this I almost shouted this into that ahem… monitor)

So, do you know the secret? :smiley:


The problem with a “while True” (or while 1=1) loop is that this doesn’t allow Panda to keep rendering the frame, resulting that the application hangs.
So, the solution to this is to put it in a task:

def yourTask(task):
  return task.cont

taskMgr.add(yourTask, "blah blah blah")

ah, so… ty

could be this added to known list of bugs please?


def update_camera(task):
    print "Delay:",task.delayTime
    print "Frame:",task.frame, viewm.getY()+20,2)
    return task.again
myTask = taskMgr.doMethodLater(1, update_camera, 'cam')


even if ‘I’ imported the module.

that’s not a bug in panda. that’s a bug in your code. so, no we cant add it, its not even a bug after all.
the manual already explains it quite well.
it’s up to you to make sure you are not locking yourself into your own while-loop (which prevents the panda-main-loop from executing).

That’s not a bug.
You must think that Panda works on a 4 dimension base: the flowing of time (igloop task, that is) is essential to define the state and positions of objects and everything else.
Putting a never-ending loop denies the flowing of time because doesn’t allow the igloop to get to the next frame, it creates an eternal still moment.


When you’ve added the task, you shouldnt call it yourself anymore. So remove that line.

I think Dany wants to execute that function immediately without waiting for the first second to pass by, and then repeat.
Just replace that “1” with the return value of the doMethodLater().

think of panda like this:

while True:
    your code

so if you put an infinite loop into your code, you never reach update_the_panda_window(), which means, everything gets repositioned, rotated and changed into infinity, but never rendered.

So I have to make panda make one time update the camera(attirbs), and then render the scene?

Is that right?

sorta yes. but the rendering will be done automatically.
if you set up a task, the task will be executed once per frame.then renders, then executes the task one, then renders once etc. what you do inside your task is up to you (for example moving the camera around)

*trying it out

or there is the taskMgr.step() function which you can call from your loop that will update the window and everything. It simply needs to be called once per loop or every couple of loops.


#your code