Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add empty sentinel item in WorkerInteractor queue #1090

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 6 additions & 1 deletion src/xdist/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def worker_title(title: str) -> None:
class Marker(enum.Enum):
SHUTDOWN = 0
QUEUE_REPLACED = 1
EMPTY = 2


class WorkerInteractor:
Expand Down Expand Up @@ -144,6 +145,8 @@ def handle_command(
self.torun.put(Marker.SHUTDOWN)
elif name == "steal":
self.steal(kwargs["indices"])
elif name == "empty":
self.torun.put(Marker.EMPTY)

def steal(self, indices: Sequence[int]) -> None:
indices_set = set(indices)
Expand Down Expand Up @@ -171,6 +174,8 @@ def pytest_runtestloop(self, session: pytest.Session) -> bool:
self.channel.setcallback(self.handle_command, endmarker=Marker.SHUTDOWN)
self.nextitem_index = self._get_next_item_index()
while self.nextitem_index is not Marker.SHUTDOWN:
while self.nextitem_index is Marker.EMPTY:
self.nextitem_index = self._get_next_item_index()
self.run_one_test()
if session.shouldfail or session.shouldstop:
break
Expand All @@ -183,7 +188,7 @@ def run_one_test(self) -> None:

items = self.session.items
item = items[self.item_index]
if self.nextitem_index is Marker.SHUTDOWN:
if self.nextitem_index in [Marker.SHUTDOWN, Marker.EMPTY]:
nextitem = None
else:
assert self.nextitem_index is not None
Expand Down
Loading