Skip to content

Commit 4d75c6a

Browse files
author
rodrigo.nogueira
committed
fix: Improve thread cleanup in proxy test fixture by simplifying thread tracking and adding post-loop garbage collection.
1 parent e63fb6d commit 4d75c6a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

tests/test_proxy_functional.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ def secure_proxy_url(tls_certificate_pem_path: str) -> Iterator[URL]:
9090
]
9191

9292
with proxy.Proxy(input_args=proxypy_args) as proxy_instance:
93-
if os.name == "nt":
94-
spawned_threads = set(threading.enumerate()) - baseline_threads
95-
9693
yield URL.build(
9794
scheme="https",
9895
host=str(proxy_instance.flags.hostname),
@@ -103,10 +100,13 @@ def secure_proxy_url(tls_certificate_pem_path: str) -> Iterator[URL]:
103100
deadline = time.monotonic() + 5.0
104101
while time.monotonic() < deadline:
105102
gc.collect()
106-
remaining = set(threading.enumerate()).intersection(spawned_threads)
107-
if not remaining:
103+
new_threads = set(threading.enumerate()) - baseline_threads
104+
if not new_threads:
108105
break
109106
time.sleep(0.05)
107+
for _ in range(3):
108+
gc.collect()
109+
time.sleep(0.1)
110110

111111

112112
@pytest.fixture

0 commit comments

Comments
 (0)