-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strip back the test to just the minimum
- Loading branch information
1 parent
a0ec220
commit dbbab41
Showing
2 changed files
with
19 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,30 @@ | ||
import gc | ||
import threading | ||
import weakref | ||
|
||
import mrc | ||
from mrc.tests.utils import ObjCallingGC | ||
from mrc.tests.utils import ObjUsingGil | ||
|
||
TLS = threading.local() | ||
|
||
|
||
class Holder: | ||
def test_gc_called_in_thread_finalizer(): | ||
mrc.logging.log("Building pipeline") | ||
|
||
def __init__(self, obj): | ||
"""Intentionally create a cycle to delay obj's destruction""" | ||
self.obj = obj | ||
self.cycle = self | ||
def source_gen(): | ||
mrc.logging.log("source_gen") | ||
x = ObjCallingGC() | ||
weakref.finalize(x, x.finalize) | ||
TLS.x = x | ||
yield x | ||
|
||
def __del__(self): | ||
mrc.logging.log("Holder.__del__") | ||
self.obj = None | ||
def init_seg(builder: mrc.Builder): | ||
builder.make_source("souce_gen", source_gen) | ||
|
||
pipe = mrc.Pipeline() | ||
pipe.make_segment("seg1", init_seg) | ||
|
||
class ThreadTest(threading.Thread): | ||
|
||
def _create_obs(self): | ||
TLS.h = Holder(ObjUsingGil()) | ||
TLS.ocg = ObjCallingGC() | ||
weakref.finalize(TLS.ocg, TLS.ocg.finalize) | ||
|
||
def run(self): | ||
mrc.logging.log("Running thread") | ||
self._create_obs() | ||
mrc.logging.log("Thread complete") | ||
|
||
|
||
def test_gil_tls(): | ||
t = ThreadTest() | ||
t.start() | ||
t.join() | ||
mrc.logging.log("Thread joined") | ||
|
||
|
||
def main(): | ||
mrc.logging.init_logging(__name__) | ||
gc.disable() | ||
gc.set_debug(gc.DEBUG_STATS) | ||
test_gil_tls() | ||
mrc.logging.log("Exiting main") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
options = mrc.Options() | ||
executor = mrc.Executor(options) | ||
executor.register_pipeline(pipe) | ||
executor.start() | ||
executor.join() |