From 26bf535fd01ca369220a6aadcdc6f4a825240497 Mon Sep 17 00:00:00 2001 From: David Gardner Date: Fri, 18 Aug 2023 10:08:17 -0700 Subject: [PATCH] Use glog to get threadid --- python/tests/test_gil_tls.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/python/tests/test_gil_tls.py b/python/tests/test_gil_tls.py index 91c933889..4c115fb2f 100644 --- a/python/tests/test_gil_tls.py +++ b/python/tests/test_gil_tls.py @@ -2,9 +2,12 @@ import threading import weakref +import mrc from mrc.tests.utils import ObjCallingGC from mrc.tests.utils import ObjUsingGil +TLS = threading.local() + class Holder: @@ -14,36 +17,37 @@ def __init__(self, obj): self.cycle = self def __del__(self): - print("Holder.__del__", flush=True) + mrc.logging.log("Holder.__del__") self.obj = None class ThreadTest(threading.Thread): def _create_obs(self): - self.h = Holder(ObjUsingGil()) - self.ocg = ObjCallingGC() - weakref.finalize(self.ocg, self.ocg.finalize) + TLS.h = Holder(ObjUsingGil()) + TLS.ocg = ObjCallingGC() + # TLS.ocg = self.ocg + weakref.finalize(TLS.ocg, TLS.ocg.finalize) def run(self): - print("Running thread", flush=True) + mrc.logging.log("Running thread") self._create_obs() - print("Thread complete", flush=True) + mrc.logging.log("Thread complete") def test_gil_tls(): t = ThreadTest() t.start() t.join() - print("Thread joined, dereferencing thread", flush=True) - t = None + mrc.logging.log("Thread joined") def main(): + mrc.logging.init_logging(__name__) gc.disable() gc.set_debug(gc.DEBUG_STATS) test_gil_tls() - print("Exiting main", flush=True) + mrc.logging.log("Exiting main") if __name__ == "__main__":