Skip to content

Commit

Permalink
Use glog to get threadid
Browse files Browse the repository at this point in the history
  • Loading branch information
dagardner-nv committed Aug 18, 2023
1 parent e3082ba commit 26bf535
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions python/tests/test_gil_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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__":
Expand Down

0 comments on commit 26bf535

Please sign in to comment.