From 66f4fc115480b1f0b922acd2d6a43fbcff614292 Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Thu, 29 Aug 2024 14:47:46 +0200 Subject: [PATCH] Use Event instead of Condition in fixture thread According to the documentation, a Condition is a bit like an Event wedded with a Lock. I believe we do not need the Lock part, because all we want is to signal the async server task in the thread to shut down. [noissue] --- pulpcore/pytest_plugin.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pulpcore/pytest_plugin.py b/pulpcore/pytest_plugin.py index 009c34b0d9..716a8bf1ea 100644 --- a/pulpcore/pytest_plugin.py +++ b/pulpcore/pytest_plugin.py @@ -166,21 +166,20 @@ async def arun(self): await runner.setup() site = web.TCPSite(runner, host=self.host, port=self.port, ssl_context=self.ssl_ctx) await site.start() - async with self.shutdown_condition: - await self.shutdown_condition.wait() + await self.shutdown_event.wait() await runner.cleanup() def run(self): asyncio.set_event_loop(self.loop) - self.shutdown_condition = asyncio.Condition() + self.shutdown_event = asyncio.Event() self.loop.run_until_complete(self.arun()) async def astop(self): - async with self.shutdown_condition: - self.shutdown_condition.notify_all() + self.shutdown_event.set() def stop(self): - asyncio.run_coroutine_threadsafe(self.astop(), self.loop) + fut = asyncio.run_coroutine_threadsafe(self.astop(), self.loop) + fut.result() class ThreadedAiohttpServerData: