Skip to content

Commit

Permalink
Use Event instead of Condition in fixture thread
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
mdellweg committed Aug 30, 2024
1 parent 567bde7 commit 66f4fc1
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pulpcore/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 66f4fc1

Please sign in to comment.