Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
'Fix' a mysterious memory leak, introduced from the previous commit
Browse files Browse the repository at this point in the history
It looks like Python's gc has some issue with a thread. Just another reason
to hate the language for me.

A brighter side is that the revised test code doesn't cause 4 seconds of
delay everytime it's invoked as it did before.
  • Loading branch information
mysticfall committed Oct 16, 2020
1 parent c3faca5 commit e5b9f9d
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions tests/test_value.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import gc
import unittest
from time import sleep

import rx
from returns.functions import identity
from rx import operators as ops

from alleycat.reactive import functions as rv, RP, RV
from alleycat.reactive.value import DATA_KEY


class ReactiveValueTest(unittest.TestCase):
Expand Down Expand Up @@ -126,39 +127,28 @@ def __init__(self, hit, *years_active, **members):
self.assertEqual(2, bangles.hits)

def test_del_hook(self):
spans = []
calls = []

class Fixture:
steeleye: RV[int] = rv.from_observable(rx.interval(1))
tick: RV[int] = rv.from_observable(rx.of(1)).map(lambda _, v: "tick!")

span: RV[str] = steeleye.map(lambda _, v: "All around my hat")

def __init__(self, values, invokes):
def __init__(self, invokes):
self.invokes = invokes

rv.observe(self, "span").subscribe(values.append)
rv.observe(self, "tick").subscribe(print)

def __del__(self):
self.invokes.append("I will wear the green willow.")
data = getattr(self, DATA_KEY)
self.invokes.append(data["tick"].disposed)

# noinspection PyUnusedLocal
fixture = Fixture(spans, calls)

sleep(2)

count = len(spans)

self.assertGreater(count, 0)
self.assertEqual([], calls)
fixture = Fixture(calls)

del fixture

self.assertEqual(["I will wear the green willow."], calls)

sleep(2)
gc.collect()

self.assertEqual(count, len(spans))
self.assertEqual([True], calls)


if __name__ == '__main__':
Expand Down

0 comments on commit e5b9f9d

Please sign in to comment.