[PATCH] D17508: [LNT] Add signal handler on main thread - by doing it at module load time.

Kristof Beyls via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 22 08:21:33 PST 2016

kristof.beyls created this revision.
kristof.beyls added a reviewer: cmatthews.
kristof.beyls added a subscriber: llvm-commits.

We've seen tracebacks like the one below on our LNT server, indicating
that previously, the code that adds the signal handler could be executed
by a thread that's not the main thread. Fix this by installing the
signal handler at module load time, which is assumed to always run in
the main thread.

  File "/lnt/lnt/server/ui/views.py", line 124, in submit_run
    current_app.old_config, g.db_name, db, path, '<auto>', commit)
  File "/lnt/lnt/util/ImportData.py", line 120, in import_and_report
    async_ops.async_fieldchange_calc(db_name, ts, run)
  File "/lnt/lnt/util/async_ops.py", line 66, in async_fieldchange_calc
  File "/lnt/lnt/util/async_ops.py", line 90, in async_run_job
  File "/lnt/lnt/util/async_ops.py", line 47, in launch_workers
    signal.signal(signal.SIGTERM, sigHandler)
ValueError: signal only works in main thread



Index: lnt/util/async_ops.py
--- lnt/util/async_ops.py
+++ lnt/util/async_ops.py
@@ -29,22 +29,21 @@
 JOBS = []
 def launch_workers():
     """Make sure we have a worker pool ready to queue."""
     global WORKERS
     if not WORKERS:
         note("Starting workers")
-        manager = Manager()         
+        manager = Manager()
-            current_app.config['mem_logger'].buffer = manager.list(current_app.config['mem_logger'].buffer)
+            current_app.config['mem_logger'].buffer = \
+                manager.list(current_app.config['mem_logger'].buffer)
         except RuntimeError:
             #  It might be the case that we are not running in the app.
             #  In this case, don't bother memory logging, stdout should
             #  sufficent for console mode.
-        atexit.register(cleanup)
-        signal.signal(signal.SIGTERM, sigHandler)
 def sigHandler(signo, frame):
@@ -57,6 +56,11 @@
         if p.is_alive:
+signal.signal(signal.SIGTERM, sigHandler)
 def async_fieldchange_calc(db_name, ts, run):
     """Run regenerate field changes in the background."""
     func_args = {'run_id': run.id}

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17508.48688.patch
Type: text/x-patch
Size: 1320 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160222/ac50abf4/attachment.bin>

More information about the llvm-commits mailing list