You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/02/04 08:25:04 UTC

[buildstream] 01/03: _messenger.py: Add a hook to explicitely start a new action context

This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch bschubert/remove-pipe-job
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit c653e3115c2da143155443464dabc6bf643885cf
Author: Benjamin Schubert <co...@benschubert.me>
AuthorDate: Mon Jan 11 09:34:56 2021 +0000

    _messenger.py: Add a hook to explicitely start a new action context
    
    This hook overrides the locals from the messenger, and ensures that we
    do not leak information between actions.
    
    This is required, as we reuse the threads between actions.
    We used to re-initialize it in the `recorded_messages` method, but that
    is an odd side effect.
    
    * job.py: Make a new context upon starting the new job
---
 src/buildstream/_messenger.py          | 4 +++-
 src/buildstream/_scheduler/jobs/job.py | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/buildstream/_messenger.py b/src/buildstream/_messenger.py
index 3bd98cd..01a8cfd 100644
--- a/src/buildstream/_messenger.py
+++ b/src/buildstream/_messenger.py
@@ -97,6 +97,9 @@ class Messenger:
         # Thread local storage
         self._locals: _MessengerLocal = _MessengerLocal()
 
+    def setup_new_action_context(self) -> None:
+        self._locals.silence_scope_depth = 0
+
     # set_message_handler()
     #
     # Sets the handler for any status messages propagated through
@@ -362,7 +365,6 @@ class Messenger:
         # Create the fully qualified logfile in the log directory,
         # appending the pid and .log extension at the end.
         self._locals.log_filename = os.path.join(logdir, "{}.{}.log".format(filename, os.getpid()))
-        self._locals.silence_scope_depth = 0
 
         # Ensure the directory exists first
         directory = os.path.dirname(self._locals.log_filename)
diff --git a/src/buildstream/_scheduler/jobs/job.py b/src/buildstream/_scheduler/jobs/job.py
index aa71b6e..227d3a2 100644
--- a/src/buildstream/_scheduler/jobs/job.py
+++ b/src/buildstream/_scheduler/jobs/job.py
@@ -493,6 +493,7 @@ class ChildJob:
         # Set the global message handler in this child
         # process to forward messages to the parent process
         self._pipe_w = pipe_w
+        self._messenger.setup_new_action_context()
         self._messenger.set_message_handler(self._child_message_handler)
 
         # Time, log and and run the action function