glib: Allow scheduling non-repeating tasks in separate threads

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Sunil Mohan Adapa 2020-04-06 20:12:34 -07:00
parent 8b721a27ef
commit 6216f7872c
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

@ -47,8 +47,9 @@ def _run():
logger.info('Glib main loop thread exited.')
def schedule(interval, method, data=None, in_thread=True):
def schedule(interval, method, data=None, in_thread=True, repeat=True):
"""Schedule a recurring call to a method with fixed interval."""
def _runner():
"""Run the target method and log and exceptions."""
try:
@ -64,6 +65,6 @@ def schedule(interval, method, data=None, in_thread=True):
thread = threading.Thread(target=_runner)
thread.start()
return True
return repeat
glib.timeout_add(int(interval * 1000), _run_bare_or_thread, None)