You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by gi...@apache.org on 2020/12/29 13:09:11 UTC
[buildstream] 08/16: job: no redundant signal code on win32
This is an automated email from the ASF dual-hosted git repository.
github-bot pushed a commit to branch aevri/win32_receive_signals
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 075cf2aaab2ee483bd4b98ba37f813de886fc51a
Author: Angelos Evripiotis <je...@bloomberg.net>
AuthorDate: Fri Oct 4 18:11:02 2019 +0100
job: no redundant signal code on win32
There's no point blocking or handling signals that aren't supported on
e.g. win32. Some of these signal ids aren't defined on unsupported
platforms though, which would lead to an AttributeError at runtime.
Avoid that by not invoking the redundant code.
---
src/buildstream/_scheduler/jobs/job.py | 35 +++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/src/buildstream/_scheduler/jobs/job.py b/src/buildstream/_scheduler/jobs/job.py
index 7d901a3..677fccc 100644
--- a/src/buildstream/_scheduler/jobs/job.py
+++ b/src/buildstream/_scheduler/jobs/job.py
@@ -200,6 +200,7 @@ class Job():
self._tries += 1
self._parent_start_listening()
+ does_platform_support_signals = self._scheduler.context.platform.does_support_signals()
child_job = self.create_child_job( # pylint: disable=assignment-from-no-return
action_name=self.action_name,
messenger=self._scheduler.context.messenger,
@@ -209,6 +210,7 @@ class Job():
tries=self._tries,
message_element_name=self._message_element_name,
message_element_key=self._message_element_key,
+ does_platform_support_signals=does_platform_support_signals,
)
if self._scheduler.context.platform.does_multiprocessing_start_require_pickling():
@@ -228,7 +230,10 @@ class Job():
# the child process does not inherit the parent's state, but the main
# process will be notified of any signal after we launch the child.
#
- with _signals.blocked([signal.SIGINT, signal.SIGTSTP, signal.SIGTERM], ignore=False):
+ if does_platform_support_signals:
+ with _signals.blocked([signal.SIGINT, signal.SIGTSTP, signal.SIGTERM], ignore=False):
+ self._process.start()
+ else:
self._process.start()
# Wait for the child task to complete.
@@ -631,7 +636,8 @@ class ChildJob():
def __init__(
self, action_name, messenger, logdir, logfile, max_retries, tries,
- message_element_name, message_element_key):
+ message_element_name, message_element_key,
+ does_platform_support_signals):
self.action_name = action_name
@@ -643,6 +649,8 @@ class ChildJob():
self._message_element_name = message_element_name
self._message_element_key = message_element_key
+ self._does_platform_support_signals = does_platform_support_signals
+
self._queue = None
# message():
@@ -732,17 +740,18 @@ class ChildJob():
#
def child_action(self, queue):
- # This avoids some SIGTSTP signals from grandchildren
- # getting propagated up to the master process
- os.setsid()
-
- # First set back to the default signal handlers for the signals
- # we handle, and then clear their blocked state.
- #
- signal_list = [signal.SIGTSTP, signal.SIGTERM]
- for sig in signal_list:
- signal.signal(sig, signal.SIG_DFL)
- signal.pthread_sigmask(signal.SIG_UNBLOCK, signal_list)
+ if self._does_platform_support_signals:
+ # This avoids some SIGTSTP signals from grandchildren
+ # getting propagated up to the master process
+ os.setsid()
+
+ # First set back to the default signal handlers for the signals
+ # we handle, and then clear their blocked state.
+ #
+ signal_list = [signal.SIGTSTP, signal.SIGTERM]
+ for sig in signal_list:
+ signal.signal(sig, signal.SIG_DFL)
+ signal.pthread_sigmask(signal.SIG_UNBLOCK, signal_list)
# Assign the queue we passed across the process boundaries
#