diff --git a/tests/memtest.py b/tests/memtest.py index 907426e..e4c20c5 100755 --- a/tests/memtest.py +++ b/tests/memtest.py @@ -72,7 +72,8 @@ def makeTestAllCurrentTld( def check() -> None: # gc.set_debug(gc.DEBUG_LEAK) - # domains = makeTestAllCurrentTld(None) + gc.set_debug(gc.DEBUG_UNCOLLECTABLE) + domains = makeTestAllCurrentTld(None) n: int = 0 before = defaultdict(int) @@ -82,22 +83,36 @@ def check() -> None: for item in domains: n += 1 print(f"Checking domain: {item}") + b2 = defaultdict(int) + for i in gc.get_objects(): + b2[type(i)] += 1 whoisdomain_call(item) + print(gc.collect(0)) # The number of unreachable objects found is returned. + print(gc.collect(1)) # The number of unreachable objects found is returned. + print(gc.collect(2)) # The number of unreachable objects found is returned. + after = defaultdict(int) for i in gc.get_objects(): after[type(i)] += 1 - z = [(k, after[k] - before[k]) for k in after if after[k] - before[k]] + z = [(k, after[k] - before[k]) for k in after if (after[k] - before[k]) > 0] + for item in z: + print("since start", item) #(, 46) is growing to 288 + + z = [(k, after[k] - b2[k]) for k in after if (after[k] - b2[k]) > 0] for item in z: - print(item) + print("since previous", item) #(, 46) is growing to 288 + + n = 0 + for item in gc.get_stats(): + print(n, item) + n += 1 - print(gc.collect()) - print(gc.get_stats()) print(gc.get_referrers()) - # print(gc.garbage) - if n > 3: - break + + for item in gc.garbage: + print("garbage:", item) @profile def whoisdomain_call(domain: str) -> None: diff --git a/whoisdomain/whoisCliInterface.py b/whoisdomain/whoisCliInterface.py index b5f5425..02bbe55 100755 --- a/whoisdomain/whoisCliInterface.py +++ b/whoisdomain/whoisCliInterface.py @@ -125,6 +125,8 @@ def _runWhoisCliOnThisOs(self) -> str: # LANG=en is added to make the ".jp" output consisent across all environments # STDBUF_OFF_CMD needed to not lose data on kill + s: string = "" + with subprocess.Popen( self.STDBUF_OFF_CMD + self._makeWhoisCommandToRun(), stdout=subprocess.PIPE, @@ -151,7 +153,10 @@ def _runWhoisCliOnThisOs(self) -> str: msg = f"timeout: query took more then {self.pc.timeout} seconds" raise WhoisCommandTimeout(msg) from ex - return self._postProcessingResult() + s = self._postProcessingResult() + + self.processHandle = None + return s def _returnWhoisPythonFromStaticTestData(self) -> str: testDir = os.getenv("TEST_WHOIS_PYTHON")