tasks and task.again

I want to have a function called every 5 seconds (just as example), I turned the function into a task, and it returns task.again.

taskMgr.doMethodLater(5,self.iteration, 'MyTaskName', extraArgs=[], appendTask=True)

The problem is that every 5 seconds, the function is called more than once, like a burst of calls: 5,5,5,5,10,10,10,10,15,15,15,15,… what makes the rest of the code not to behave in the expected way.

It’s not very hard to get a workaround, but I wanted to ask if this is normal and the more elegant way to fix that into my wanted calling scheme.

Thanks in advance

task go for every frame not time soo it calls every frame i think i just starting to work with them running in to other problems xD

@kingking190: depends on your task. doMethodLater is exactly the right thing for running a task after x seconds.

eric48k: i dont know exactly what the appendTask parameter does. but what definetly works is to call the doMethodLater from inside your task and then finish the task.

    taskMgr.doMethodLater( blabla )
    return Task.done  

Task.again !might! do the same but not sure about that one at all.

code is from an old snippset of mine so there might be a better way to do it.

Thanks for your replies.

appendTask is used to pass task as argument so you can do whatever you need with it. It has nothing to do with the problem, or so I think.

@Thomas. I’ve tried the workaround you suggest, it doesn’t seem to make any difference. Maybe it’s something in my code. I’ll have a closer look.

It’s somehow a curious issue. I think task manager compares its estimated time for re-call to elapsed time, when it’s equal, the task is called, if it’s so fast that when time is re-evaluated, it’s still just a bit past the time, it’s called again until time is clearly out of the correct time frame. (just theories)

Believe it or not, I was about to ask this same question (have a task I need to run every few seconds) - will try Thomas’ suggestion.

Hmm sorry :blush: , my code was calling doMethodlater more than once, hence those multiple calls.

What I learned today: If you hava a doMethodLater depending on keystrokes, put it this way:

if taskMgr.hasTaskNamed('MyTaskName')==0:
        taskMgr.doMethodLater(3,self.iteration, 'MyTaskName', extraArgs=[], appendTask=True)