Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions test/asynchronous/utils_spec_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,30 @@ def __init__(self, name):
self.ops = []

async def schedule(self, work):
self.ops.append(work)
async with self.cond:
self.ops.append(work)
self.cond.notify()

async def stop(self):
self.stopped = True
async with self.cond:
self.stopped = True
self.cond.notify()

async def run(self):
while not self.stopped or self.ops:
if not self.ops:
async with self.cond:
while True:
# Check ops and stopped while holding the lock so a notify() from
# schedule() or stop() can't be missed before the wait starts.
async with self.cond:
while not self.ops and not self.stopped:
Comment thread
NoahStapp marked this conversation as resolved.
await _async_cond_wait(self.cond, 10)
if self.ops:
try:
work = self.ops.pop(0)
await work()
except Exception as exc:
self.exc = exc
await self.stop()
if not self.ops:
break
work = self.ops.pop(0)
try:
await work()
except Exception as exc:
self.exc = exc
await self.stop()


class AsyncSpecTestCreator:
Expand Down
27 changes: 15 additions & 12 deletions test/utils_spec_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,30 @@ def __init__(self, name):
self.ops = []

def schedule(self, work):
self.ops.append(work)
with self.cond:
self.ops.append(work)
self.cond.notify()

def stop(self):
self.stopped = True
with self.cond:
self.stopped = True
self.cond.notify()

def run(self):
while not self.stopped or self.ops:
if not self.ops:
with self.cond:
while True:
# Check ops and stopped while holding the lock so a notify() from
# schedule() or stop() can't be missed before the wait starts.
with self.cond:
while not self.ops and not self.stopped:
_cond_wait(self.cond, 10)
if self.ops:
try:
work = self.ops.pop(0)
work()
except Exception as exc:
self.exc = exc
self.stop()
if not self.ops:
break
work = self.ops.pop(0)
try:
work()
except Exception as exc:
self.exc = exc
self.stop()


class SpecTestCreator:
Expand Down
Loading