# Released under the MIT License. See LICENSE for details.#"""Debugging functionality."""from__future__importannotationsfromtypingimportTYPE_CHECKINGimportbabaseifTYPE_CHECKING:fromtypingimportAnyimportbascenev1
[docs]defprint_live_object_warnings(when:Any,ignore_session:bascenev1.Session|None=None,ignore_activity:bascenev1.Activity|None=None,)->None:"""Print warnings for remaining objects in the current context. IMPORTANT - don't call this in production; usage of gc.get_objects() can bork Python. See notes at top of efro.debug module. """# pylint: disable=cyclic-importimportgcfrombascenev1._sessionimportSessionfrombascenev1._actorimportActorfrombascenev1._activityimportActivityassertbabase.app.classicisnotNonesessions:list[bascenev1.Session]=[]activities:list[bascenev1.Activity]=[]actors:list[bascenev1.Actor]=[]# Once we come across leaked stuff, printing again is probably# redundant.ifbabase.app.classic.printed_live_object_warning:returnforobjingc.get_objects():ifisinstance(obj,Actor):actors.append(obj)elifisinstance(obj,Session):sessions.append(obj)elifisinstance(obj,Activity):activities.append(obj)# Complain about any remaining sessions.forsessioninsessions:ifsessionisignore_session:continuebabase.app.classic.printed_live_object_warning=Trueprint(f'ERROR: Session found {when}: {session}')# Complain about any remaining activities.foractivityinactivities:ifactivityisignore_activity:continuebabase.app.classic.printed_live_object_warning=Trueprint(f'ERROR: Activity found {when}: {activity}')# Complain about any remaining actors.foractorinactors:babase.app.classic.printed_live_object_warning=Trueprint(f'ERROR: Actor found {when}: {actor}')
# Docs-generation hack; import some stuff that we likely only forward-declared# in our actual source code so that docs tools can find it.fromtypingimport(Coroutine,Any,Literal,Callable,Generator,Awaitable,Sequence,Self)importasynciofromconcurrent.futuresimportFuture