Skip to content

Commit

Permalink
testing mem leak
Browse files Browse the repository at this point in the history
  • Loading branch information
mboot-github committed Feb 5, 2024
1 parent 3e0d60e commit d760314
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
31 changes: 23 additions & 8 deletions tests/memtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) #(<class 're.Pattern'>, 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) #(<class 're.Pattern'>, 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:
Expand Down
7 changes: 6 additions & 1 deletion whoisdomain/whoisCliInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down

0 comments on commit d760314

Please sign in to comment.