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

Flush the merge-wait queue on SIGUSR2 #1406

Closed
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
23 changes: 19 additions & 4 deletions lib/_emerge/Scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ def __init__(
# empty.
self._merge_wait_scheduled = []

self._flush_merge_wait_queue = False

# Holds system packages and their deep runtime dependencies. Before
# being merged, these packages go to merge_wait_queue, to be merged
# when no other packages are building.
Expand Down Expand Up @@ -1170,12 +1172,16 @@ def sighandler(signum, frame):
self.terminate()
received_signal.append(128 + signum)

def sigusr2handler(signum, frame):
self._flush_merge_wait_queue = True

earlier_sigint_handler = signal.signal(signal.SIGINT, sighandler)
earlier_sigterm_handler = signal.signal(signal.SIGTERM, sighandler)
earlier_sigcont_handler = signal.signal(
signal.SIGCONT, self._sigcont_handler
)
signal.siginterrupt(signal.SIGCONT, False)
earlier_sigusr2_handler = signal.signal(signal.SIGUSR2, sigusr2handler)

try:
rval = self._merge()
Expand All @@ -1193,6 +1199,10 @@ def sighandler(signum, frame):
signal.signal(signal.SIGCONT, earlier_sigcont_handler)
else:
signal.signal(signal.SIGCONT, signal.SIG_DFL)
if earlier_sigusr2_handler is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to do this now, but I wonder if we could do bette rwith this with a context manager.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would require creating a custom context manager class for signals, right?

signal.signal(signal.SIGUSR2, earlier_sigusr2_handler)
else:
signal.signal(signal.SIGUSR2, signal.SIG_DFL)

self._termination_check()
if received_signal:
Expand Down Expand Up @@ -1809,11 +1819,16 @@ def _schedule_tasks(self):
# special packages and we want to ensure that
# parallel-install does not cause more than one of
# them to install at the same time.
if (
self._merge_wait_queue
and not self._jobs
and not self._task_queues.merge
if self._merge_wait_queue and (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be nice as a variable instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I understand. "This" being _merge_wait_queue and you want something like merge_wait_queue_not_empty?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the whole expression is pretty icky over multiple lines (although this is partly Black's fault).

(not self._jobs and not self._task_queues.merge)
or self._flush_merge_wait_queue
):
if self._flush_merge_wait_queue:
self._status_msg(
"Manual flush of the merge-wait queue requested (e.g., via SIGUSR2)"
)
self._flush_merge_wait_queue = False

while self._merge_wait_queue:
# If we added non-system packages to the merge queue in a
# previous iteration of this loop, then for system packages we
Expand Down
Loading