Skip to content

Commit

Permalink
fix(plugin.py): Clear all references for a queue using gc.get_referre…
Browse files Browse the repository at this point in the history
…rs, similar to the issue described at https://bugs.python.org/issue33081
  • Loading branch information
igor udot (horw) committed Oct 27, 2023
1 parent 83ccfe6 commit 27411b0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pytest-embedded/pytest_embedded/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime
import dbm
import functools
import gc
import importlib
import io
import logging
Expand Down Expand Up @@ -409,6 +410,17 @@ def _close_or_terminate(obj):
return

try:
referrers = gc.get_referrers(obj)
for _referrer in referrers:
if isinstance(_referrer, list):
for _i, val in enumerate(_referrer):
if val is obj:
_referrer[_i] = None
elif isinstance(_referrer, dict):
for key, value in _referrer.items():
if value is obj:
_referrer[key] = None

if isinstance(obj, (subprocess.Popen, multiprocessing.process.BaseProcess)):
obj.terminate()
obj.kill()
Expand Down

0 comments on commit 27411b0

Please sign in to comment.