Skip to content

Commit 85a390f

Browse files
authored
Merge pull request #446 from kimocoder/claude/fix-pytest-hanging-c9xQe
fix: prevent pytest hanging by avoiding threading.Lock in Process.__d…
2 parents 9bcd4ee + cde1534 commit 85a390f

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

wifite/util/process.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,33 @@ def __exit__(self, exc_type, exc_val, exc_tb):
212212
self.cleanup()
213213

214214
def __del__(self):
215+
# During interpreter shutdown, module globals (including threading)
216+
# may already be torn down. Acquiring a threading.Lock in that state
217+
# can trigger an infinite-restart loop, so we only do lightweight
218+
# cleanup here and skip ProcessManager.unregister_process entirely
219+
# (the atexit handler already handles bulk cleanup).
215220
try:
216-
self.cleanup()
221+
if getattr(self, '_cleaned_up', True):
222+
return
223+
# Best-effort: kill still-running subprocesses and close FDs
224+
if hasattr(self, 'pid') and self.pid:
225+
try:
226+
if self.pid.poll() is None:
227+
self.pid.kill()
228+
self.pid.wait()
229+
except Exception:
230+
pass
231+
for stream in (self.pid.stdin, self.pid.stdout, self.pid.stderr):
232+
if stream:
233+
try:
234+
stream.close()
235+
except Exception:
236+
pass
237+
for fh in getattr(self, '_devnull_handles', []):
238+
try:
239+
fh.close()
240+
except Exception:
241+
pass
217242
except Exception:
218243
pass
219244

0 commit comments

Comments
 (0)