From 785f4d11f13564f95ce66bec5ac0d235583eba0f Mon Sep 17 00:00:00 2001 From: Olivier Martin Date: Wed, 13 Mar 2024 13:00:48 +0100 Subject: [PATCH] gattlib-py/gattlib/mainloop: Ensure we are not overwriting the mainloop --- gattlib-py/gattlib/mainloop.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gattlib-py/gattlib/mainloop.py b/gattlib-py/gattlib/mainloop.py index 33703097..961fc95c 100644 --- a/gattlib-py/gattlib/mainloop.py +++ b/gattlib-py/gattlib/mainloop.py @@ -42,6 +42,9 @@ def _user_thread_main(task): def run_mainloop_with(task): global gobject_mainloop, task_returned_code, task_exception + if gobject_mainloop: + raise RuntimeError("A mainloop is already running") + # Ensure GLib's threading is initialized to support python threads, and # make a default mainloop that all DBus objects will inherit. These # commands MUST execute before any other DBus commands! @@ -70,3 +73,5 @@ def run_mainloop_with(task): # We assume that if we exit with keyboard interrupt than it is not the expected # behaviour and we return -1 return -2 + finally: + gobject_mainloop = None