From 27411b05fa59bbca6210f7fded334e48fd06d3b5 Mon Sep 17 00:00:00 2001 From: "igor udot (horw)" Date: Fri, 27 Oct 2023 12:30:04 +0800 Subject: [PATCH] fix(plugin.py): Clear all references for a queue using gc.get_referrers, similar to the issue described at https://bugs.python.org/issue33081 --- pytest-embedded/pytest_embedded/plugin.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pytest-embedded/pytest_embedded/plugin.py b/pytest-embedded/pytest_embedded/plugin.py index 5fba0f5a..f87a12ff 100644 --- a/pytest-embedded/pytest_embedded/plugin.py +++ b/pytest-embedded/pytest_embedded/plugin.py @@ -2,6 +2,7 @@ import datetime import dbm import functools +import gc import importlib import io import logging @@ -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()