gecko-dev/python
Andrew Halberstadt 35ace05949 Bug 1369711 - [mozlint] Make sure KeyboardInterrupts are handled well wherever they happen r=gps
There a few pieces needed here to properly handle KeyboardInterrupts.

1. All in-progress work needs to abort. Ideally the underlying linters will be
able to catch KeyboardInterrupt, and return partial results (like the flake8
linter does). Linters may alternatively allow the KeyboardInterrupt to
propagate up. Mozlint will catch and handle this appropriately, though any
results found will be lost. The only change to this behaviour was fixing a bug
in the flake8 linter.

2. Any unstarted jobs need to be canceled. In concurrent.futures, there are two
different queues. First, jobs are placed on the work queue, which is just a list
maintained by the parent process. As workers become available, jobs are moved
off the work queue, and onto the call queue (which is a multiprocessing.Queue).
Jobs that live on the work queue can be canceled with 'future.cancel()', whereas
jobs that live on the call queue cannot. The number of extra jobs that are stored
on the call queue is determined by this variable:
https://hg.mozilla.org/mozilla-central/file/deb7714a7bcd/third_party/python/futures/concurrent/futures/process.py#l86

In this patch, the parent process' sigint handler (which will be called on Ctrl-C)
is responsible for canceling all the jobs on the work queue. For the jobs on the
call queue, the best we can do is set a global variable that tells workers to
abort early.

3. Idle workers should exit gracefully. When there are no more jobs left, workers
will block on the call queue (either waiting for more jobs, or waiting for the
executor to send the shutdown signal). If a KeyboardInterrupt is received while a
worker is blocking, it isn't possible to intercept that anywhere (due to quirks
of how concurrent.futures is implemented). The InterruptableQueue class was
created to solve this problem. It will return None instead of propagating
KeyboardInterrupt. A None value will wake the worker up and tell it to gracefully
shutdown. This way, we avoid cryptic tracebacks in the output.

With all of these various pieces solved, pressing Ctrl-C appears to always exit
gracefully, sometimes even printing partial results.

MozReview-Commit-ID: 36Pe3bbUKmk

--HG--
extra : rebase_source : d4c312ee5cc3679eeee1407c5521aed679f84ad4
extra : source : a93a00141bf62f6bc9e30934c0e56f6b2e434bf0
2018-02-23 08:55:06 -05:00
..
devtools/migrate-l10n
l10n/fluent_migrations Bug 1445084 - Migrate search results pane of Preferences to Fluent. r=flod,Gijs 2018-03-12 16:27:32 -07:00
mach Bug 1434430 - [flake8] Fix blank 'except' statements r=rwood 2018-01-31 14:32:08 -05:00
mozboot Bug 1444881 - Make |mach bootstrap| use the latest version of Oracle's JDK when bootstrapping Fennec on Gentoo; r=nalexander 2018-03-12 14:31:05 +01:00
mozbuild Bug 1445763 - Update moz.build meta data with "Firefox Build System". r=froydnj 2018-03-14 21:44:46 +01:00
mozlint Bug 1369711 - [mozlint] Make sure KeyboardInterrupts are handled well wherever they happen r=gps 2018-02-23 08:55:06 -05:00
mozrelease bug 1398799: mozharness script to create update verify configs without relying on patcher configs. r=nthomas 2018-02-23 06:00:02 -05:00
mozterm Bug 1434430 - [flake8] Fix blank 'except' statements r=rwood 2018-01-31 14:32:08 -05:00
mozversioncontrol Bug 1405588 - [mozversioncontrol] Use base_ref instead of upstream as default outgoing comparison on git, r=gps 2017-11-01 12:57:03 -04:00
README
mach_commands.py Bug 1446471 - Remove unused import; r=nalexander 2018-03-06 19:15:42 -08:00
moz.build Bug 1445763 - Update moz.build meta data with "Firefox Build System". r=froydnj 2018-03-14 21:44:46 +01:00

README

This directory contains common Python code.

The basic rule is that if Python code is cross-module (that's "module" in the
Mozilla meaning - as in "module ownership") and is MPL-compatible, it should
go here.

What should not go here:

* Vendored python modules (use third_party/python instead)
* Python that is not MPL-compatible (see other-licenses/)
* Python that has good reason to remain close to its "owning" (Mozilla)
  module (e.g. it is only being consumed from there).

Historical information can be found at
https://bugzilla.mozilla.org/show_bug.cgi?id=775243
https://bugzilla.mozilla.org/show_bug.cgi?id=1346025