[Git][reproducible-builds/diffoscope][master] 4 commits: Clarify control flow in diffoscope.profiling.

Chris Lamb (@lamby) gitlab at salsa.debian.org
Wed Jun 8 07:11:29 UTC 2022



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
3e7491bd by Chris Lamb at 2022-06-08T08:06:17+01:00
Clarify control flow in diffoscope.profiling.

- - - - -
c26ac469 by Chris Lamb at 2022-06-08T08:07:53+01:00
Clarify in what situations the main "finally" block gets called with respect to TERM handling.

- - - - -
d77ff3a3 by Chris Lamb at 2022-06-08T08:10:14+01:00
Emit a warning if/when we are handling a TERM signal.

- - - - -
0fc439ee by Chris Lamb at 2022-06-08T08:10:52+01:00
Print profile output if we were called with --profile and we were killed via TERM.

- - - - -


2 changed files:

- diffoscope/main.py
- diffoscope/profiling.py


Changes:

=====================================
diffoscope/main.py
=====================================
@@ -726,7 +726,10 @@ def run_diffoscope(parsed_args):
 
 
 def sigterm_handler(signo, stack_frame):
+    logger.warning("Received TERM signal; cleaning up temp files...")
     clean_all_temp_files()
+    ProfileManager().finish()
+    logger.warning("Exiting...")
     os._exit(2)
 
 
@@ -781,6 +784,9 @@ def main(args=None):
             pdb.post_mortem()
         sys.exit(2)
     finally:
+        # Note that this is block is not called if the sigterm_handler method
+        # is a) called, and b) executes successfully.
+
         # Helps our tests run more predictably - some of them call main()
         # which sets Config() values.
         Config().reset()


=====================================
diffoscope/profiling.py
=====================================
@@ -60,16 +60,25 @@ class ProfileManager:
         self.data[namespace][key]["time"] += time.time() - start
         self.data[namespace][key]["count"] += 1
 
-    def finish(self, parsed_args):
+    def finish(self, parsed_args=None):
         from .presenters.utils import make_printer
 
+        # We are being called in the TERM handler so we don't have access to
+        # parsed_args. Print the profiling output to stderr if we have been
+        # collecting it.
+        if parsed_args is None:
+            if _ENABLED:
+                self.output(lambda x: print(x, file=sys.stderr))
+            return
+
         # Include profiling in --debug output if --profile is not set.
         if parsed_args.profile_output is None:
             with setup_logging(parsed_args.debug, None) as logger:
                 self.output(lambda x: logger.debug(x.strip("\n")))
-        else:
-            with make_printer(parsed_args.profile_output) as fn:
-                self.output(fn)
+            return
+
+        with make_printer(parsed_args.profile_output) as fn:
+            self.output(fn)
 
     def output(self, print_fn):
         title = "# Profiling output for: {}".format(" ".join(sys.argv))



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/22aba2285f81092696fb57107041cdb0e3bff69a...0fc439ee035ae9ef657054f8747caf774a5772ee

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/22aba2285f81092696fb57107041cdb0e3bff69a...0fc439ee035ae9ef657054f8747caf774a5772ee
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20220608/0b3dc5b4/attachment.htm>


More information about the rb-commits mailing list