## Copyright (c) 2016-2025 Deephaven Data Labs and Patent Pending#"""This module allows user to enable/disable Deephaven systemic object marking. When enabled, Deephaven will markall objects created in the current thread as systemic. These systemic objects will be tracked and if errors occur tothem, the errors are deemed to be systemic and fatal."""importcontextlibimportjpyfromdeephavenimportDHError_JSystemicObjectTracker=jpy.get_type("io.deephaven.engine.util.systemicmarking.SystemicObjectTracker")
[docs]defis_systemic_object_marking_enabled()->bool:"""Returns True if the systemic object marking is enabled. When enabled, the current thread can be marked as systemic or not systemic. """return_JSystemicObjectTracker.isSystemicObjectMarkingEnabled()
[docs]defis_systemic()->bool:"""Returns whether the current thread is systemic. If true, objects created on this thread are treated as systemic."""return_JSystemicObjectTracker.isSystemicThread()
[docs]defset_systemic(systemic:bool)->None:"""Sets whether the current thread is systemic. If true, objects created on this thread are treated as systemic. Args: systemic (bool): True to mark the current thread as systemic, False to mark it as not systemic. Raises: DHError: If the systemic object marking is not enabled. """ifis_systemic_object_marking_enabled():ifsystemic:_JSystemicObjectTracker.markThreadSystemic()else:_JSystemicObjectTracker.markThreadNotSystemic()else:raiseDHError(message="Systemic object marking is not enabled.")
[docs]@contextlib.contextmanagerdefsystemic_object_marking()->None:"""A Context manager to ensure the current thread is marked as systemic for the execution of the enclosed code block. On exit, the thread is restored to its previous systemic state. Raises: DHError: If the systemic object marking is not enabled. """ifis_systemic_object_marking_enabled():ifnotis_systemic():try:_JSystemicObjectTracker.markThreadSystemic()yieldfinally:_JSystemicObjectTracker.markThreadNotSystemic()else:yieldelse:raiseDHError(message="Systemic object marking is not enabled.")
[docs]@contextlib.contextmanagerdefno_systemic_object_marking()->None:"""A Context manager to ensure the current thread is marked as not systemic for the execution of the enclosed code block. On exit, the thread is restored to its previous systemic state. Raises: DHError: If the systemic object marking is not enabled. """ifis_systemic_object_marking_enabled():ifis_systemic():try:_JSystemicObjectTracker.markThreadNotSystemic()yieldfinally:_JSystemicObjectTracker.markThreadSystemic()else:yieldelse:raiseDHError(message="Systemic object marking is not enabled.")