fix: allow access to state's exit_event while exiting

When exiting, the state's `is_initialized` flag is unset. Noticeable on Windows, when a thread tried to access the state's `exit_event` property to check whether it had been set, it would complain that the state was no longer initialized. Now, even when no longer initialized, if the `exit_event` is set, it will not raise an error when accessing this attribute.

ref: N25B-119
This commit is contained in:
Twirre Meulenbelt
2025-10-01 17:34:51 +02:00
parent d21c7fa423
commit 2132a74321

View File

@@ -37,7 +37,12 @@ class State(object):
if name in ("initialize", "deinitialize", "is_initialized", "__dict__", "__class__"): if name in ("initialize", "deinitialize", "is_initialized", "__dict__", "__class__"):
return object.__getattribute__(self, name) return object.__getattribute__(self, name)
if not self.is_initialized: if not object.__getattribute__(self, "is_initialized"):
# Special case for the exit_event: if the event is set, return it without an error
if name == "exit_event":
exit_event = object.__getattribute__(self, "exit_event")
if exit_event and exit_event.is_set(): return exit_event
raise RuntimeError("State must be initialized before accessing '%s'" % name) raise RuntimeError("State must be initialized before accessing '%s'" % name)
return object.__getattribute__(self, name) return object.__getattribute__(self, name)