Update
Some checks failed
DevPlace CI / test (push) Failing after 1h32m13s

This commit is contained in:
retoor 2026-08-16 05:00:52 +02:00
parent 62910b0726
commit d7d489681a

View File

@ -41,32 +41,50 @@ os.environ["DEVPLACE_RANKING_TTL"] = "0"
os.environ["DEVPLACE_MARKET_SATURATION_TTL"] = "0" os.environ["DEVPLACE_MARKET_SATURATION_TTL"] = "0"
_ASYNC_LOOP = None
_ASYNC_LOOP_LOCK = threading.Lock()
def _async_loop():
# One shared background loop thread for the whole session, not one thread
# per run_async() call: dataset's NullPool caches one SQLite connection per
# OS thread ID forever (see the root CLAUDE.md NullPool note), so a fresh
# throwaway thread per call - this helper is invoked 270+ times across the
# suite - permanently claimed one file descriptor apiece for the rest of
# the session and could exhaust the process's open-file limit on a long run.
global _ASYNC_LOOP
with _ASYNC_LOOP_LOCK:
if _ASYNC_LOOP is None:
loop = asyncio.new_event_loop()
threading.Thread(
target=loop.run_forever, name="run-async-loop", daemon=True
).start()
_ASYNC_LOOP = loop
return _ASYNC_LOOP
def run_async(coro): def run_async(coro):
"""Run a coroutine from sync test code on a dedicated thread and fresh loop.""" """Run a coroutine from sync test code on the shared background loop."""
result_box = []
exc_box = [] async def _wrapped():
from devplacepy.database import refresh_snapshot
def _run():
try: try:
result_box.append(asyncio.run(coro)) return await coro
except BaseException as e:
exc_box.append(e)
finally: finally:
from devplacepy.database import refresh_snapshot
refresh_snapshot() refresh_snapshot()
t = threading.Thread(target=_run, daemon=True) future = asyncio.run_coroutine_threadsafe(_wrapped(), _async_loop())
t.start() try:
t.join(timeout=30) return future.result(timeout=30)
from devplacepy.database import refresh_snapshot except TimeoutError:
raise TimeoutError(
"run_async timed out waiting for coroutine to complete"
) from None
finally:
from devplacepy.database import refresh_snapshot
refresh_snapshot() refresh_snapshot()
if exc_box:
raise exc_box[0]
if result_box:
return result_box[0]
raise TimeoutError("run_async timed out waiting for coroutine to complete")
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)