You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:45:14 UTC

[buildstream] 16/16: signal debug

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

not-in-ldap pushed a commit to branch tpollard/buildsubtemp
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit aae4bbc4342dc4d30e2081279c26e34a6150db30
Author: Tom Pollard <to...@codethink.co.uk>
AuthorDate: Tue Oct 29 16:03:46 2019 +0000

    signal debug
---
 src/buildstream/_frontend/app.py        | 8 +++++---
 src/buildstream/_scheduler/scheduler.py | 5 +++++
 src/buildstream/_stream.py              | 3 +++
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/buildstream/_frontend/app.py b/src/buildstream/_frontend/app.py
index e146de9..d8ec3e7 100644
--- a/src/buildstream/_frontend/app.py
+++ b/src/buildstream/_frontend/app.py
@@ -518,14 +518,16 @@ class App():
 
             try:
                 choice = click.prompt("Choice:",
-                                      value_proc=_prefix_choice_value_proc(['continue', 'quit', 'terminate']),
+                                      value_proc=_prefix_choice_value_proc(['continue', 'quit', 'terminate', 'e']),
                                       default='continue', err=True)
             except click.Abort:
                 # Ensure a newline after automatically printed '^C'
                 click.echo("", err=True)
                 choice = 'terminate'
-
-            if choice == 'terminate':
+            if choice == 'e':
+                from traceback import print_stack
+                print_stack(file=sys.stderr)
+            elif choice == 'terminate':
                 click.echo("\nTerminating all jobs at user request\n", err=True)
                 self.stream.terminate()
             else:
diff --git a/src/buildstream/_scheduler/scheduler.py b/src/buildstream/_scheduler/scheduler.py
index 3640d7b..2fe6532 100644
--- a/src/buildstream/_scheduler/scheduler.py
+++ b/src/buildstream/_scheduler/scheduler.py
@@ -534,6 +534,7 @@ class Scheduler():
 
         if not self._notify_front_queue:
             # Not running in a subprocess, scheduler process to handle keyboard interrupt
+            print("Scheduler called an interrupt")
             notification = Notification(NotificationType.INTERRUPT)
             self._notify_front(notification)
 
@@ -566,15 +567,19 @@ class Scheduler():
     # Connects our signal handler event callbacks to the mainloop
     #
     def _connect_signals(self):
+        print("sched is connecting {}".format(os.getpid()))
         self.loop.add_signal_handler(signal.SIGINT, self._interrupt_event)
         self.loop.add_signal_handler(signal.SIGTERM, self._terminate_event)
         self.loop.add_signal_handler(signal.SIGTSTP, self._suspend_event)
 
     def _disconnect_signals(self):
+        print("sched is disconnecting {}".format(os.getpid()))
         self.loop.remove_signal_handler(signal.SIGINT)
         self.loop.remove_signal_handler(signal.SIGTSTP)
         self.loop.remove_signal_handler(signal.SIGTERM)
 
+        signal.signal(signal.SIGINT, signal.SIG_IGN)
+
     def _terminate_jobs_real(self):
         # 20 seconds is a long time, it can take a while and sometimes
         # we still fail, need to look deeper into this again.
diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py
index 21c5410..b5d2cd2 100644
--- a/src/buildstream/_stream.py
+++ b/src/buildstream/_stream.py
@@ -1860,6 +1860,7 @@ class Stream():
 
     def _connect_signals(self):
         if self.loop:
+            print("stream is connecting {}".format(os.getpid()))
             self.loop.add_signal_handler(signal.SIGINT, self._interrupt_callback)
             self.loop.add_signal_handler(signal.SIGTERM,
                                          lambda: self._notify_back(Notification(NotificationType.TERMINATE)))
@@ -1868,9 +1869,11 @@ class Stream():
 
     def _disconnect_signals(self):
         if self.loop:
+            print("stream is disconnecting {}".format(os.getpid()))
             self.loop.remove_signal_handler(signal.SIGINT)
             self.loop.remove_signal_handler(signal.SIGTSTP)
             self.loop.remove_signal_handler(signal.SIGTERM)
+            #signal.signal(signal.SIGINT, signal.SIG_IGN)
 
     def __getstate__(self):
         # The only use-cases for pickling in BuildStream at the time of writing