pythonpython-3.xconcurrencykivykivy-language

Schedule a Job to be done after every 5 seconds in Python(Kivy)


I Want to schedule a Job to be done after every 5 seconds which takes around 3 seconds to execute. I have used

kivy.uix.clock.Clock.schedule_interval(my_job, 5)

and

def my_Job():
   # Job Statements
   time.sleep(5)
   my_job()
my_thread = threading.Thread(target=my_Job)
my_thread.start()

so far. But first one block's my design as it get executed in main Thread and second one reach

RecursionError: maximum recursion depth exceeded while calling a Python object

in a long run. I am stuck here, Is there anyone to help me ? Thanks

Note: I am using kivy to develop a desktop app.


Solution

  • You can use sched. See the documentation. Note that you should not to anything that changes the kivy GUI in my_job() when run this way. But you can call Clock.schedule_once() from my_job to do just the GUI stuff.