Skip to content

Commit

Permalink
Inhibit OS error reporting in python processes.
Browse files Browse the repository at this point in the history
For now it is Windows specific but the hook is OS agnostic. Call it at the start
of all processes. This prevents a OS-induced hang on crash, which is very
annoying to get through.

Put in subprocess42 so the function can be called from all of our scripts easily
without having to copy paste it everywhere.

[email protected]
BUG=

Review-Url: https://codereview.chromium.org/2012673002
  • Loading branch information
maruel authored and Commit bot committed May 30, 2016
1 parent 5c6162e commit 2ac1033
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions appengine/swarming/swarming_bot/bot_code/bot_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ def get_config():


def main(args):
subprocess42.inhibit_os_error_reporting()
# Add SWARMING_HEADLESS into environ so subcommands know that they are running
# in a headless (non-interactive) mode.
os.environ['SWARMING_HEADLESS'] = '1'
Expand Down
1 change: 1 addition & 0 deletions appengine/swarming/swarming_bot/bot_code/task_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ def run_command(


def main(args):
subprocess42.inhibit_os_error_reporting()
parser = optparse.OptionParser(description=sys.modules[__name__].__doc__)
parser.add_option('--in-file', help='Name of the request file')
parser.add_option(
Expand Down
2 changes: 2 additions & 0 deletions client/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from utils import on_error
from utils import net
from utils import oauth
from utils import subprocess42
from utils import tools


Expand Down Expand Up @@ -175,6 +176,7 @@ def main(args):


if __name__ == '__main__':
subprocess42.inhibit_os_error_reporting()
fix_encoding.fix_encoding()
tools.disable_buffering()
colorama.init()
Expand Down
2 changes: 2 additions & 0 deletions client/isolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from utils import logging_utils
from utils import file_path
from utils import fs
from utils import subprocess42
from utils import tools


Expand Down Expand Up @@ -1218,6 +1219,7 @@ def main(argv):


if __name__ == '__main__':
subprocess42.inhibit_os_error_reporting()
fix_encoding.fix_encoding()
tools.disable_buffering()
colorama.init()
Expand Down
2 changes: 2 additions & 0 deletions client/isolateserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from utils import lru
from utils import net
from utils import on_error
from utils import subprocess42
from utils import threading_utils
from utils import tools

Expand Down Expand Up @@ -2268,6 +2269,7 @@ def main(args):


if __name__ == '__main__':
subprocess42.inhibit_os_error_reporting()
fix_encoding.fix_encoding()
tools.disable_buffering()
colorama.init()
Expand Down
1 change: 1 addition & 0 deletions client/run_isolated.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ def main(args):


if __name__ == '__main__':
subprocess42.inhibit_os_error_reporting()
# Ensure that we are always running with the correct encoding.
fix_encoding.fix_encoding()
sys.exit(main(sys.argv[1:]))
2 changes: 2 additions & 0 deletions client/swarming.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from third_party.chromium import natsort
from utils import net
from utils import on_error
from utils import subprocess42
from utils import threading_utils
from utils import tools

Expand Down Expand Up @@ -1528,6 +1529,7 @@ def main(args):


if __name__ == '__main__':
subprocess42.inhibit_os_error_reporting()
fix_encoding.fix_encoding()
tools.disable_buffering()
colorama.init()
Expand Down
2 changes: 2 additions & 0 deletions client/trace_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from utils import file_path
from utils import fs
from utils import logging_utils
from utils import subprocess42
from utils import tools

## OS-specific imports
Expand Down Expand Up @@ -3397,6 +3398,7 @@ def main(argv):


if __name__ == '__main__':
subprocess42.inhibit_os_error_reporting()
fix_encoding.fix_encoding()
tools.disable_buffering()
colorama.init()
Expand Down
34 changes: 34 additions & 0 deletions client/utils/subprocess42.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def wait_terminate_then_kill(proc, timeout, grace):
import errno
import os
import signal
import sys
import threading
import time

Expand All @@ -44,7 +45,12 @@ def wait_terminate_then_kill(proc, timeout, grace):
MAX_SIZE = 16384


# Set to True when inhibit_crash_dump() has been called.
_OS_ERROR_REPORTING_INHIBITED = False


if subprocess.mswindows:
import ctypes
import msvcrt # pylint: disable=F0401
from ctypes import wintypes
from ctypes import windll
Expand Down Expand Up @@ -601,3 +607,31 @@ def call_with_timeout(args, timeout, **kwargs):
proc.kill()
proc.wait()
return out, err, proc.returncode, proc.duration()


def inhibit_os_error_reporting():
"""Inhibits error reporting UI and core files.
This function should be called as early as possible in the process lifetime.
"""
global _OS_ERROR_REPORTING_INHIBITED
if not _OS_ERROR_REPORTING_INHIBITED:
_OS_ERROR_REPORTING_INHIBITED = True
if sys.platform == 'win32':
# Windows has a bad habit of opening a dialog when a console program
# crashes, rather than just letting it crash. Therefore, when a program
# crashes on Windows, we don't find out until the build step times out.
# This code prevents the dialog from appearing, so that we find out
# immediately and don't waste time waiting for a user to close the dialog.
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms680621.aspx
SEM_FAILCRITICALERRORS = 1
SEM_NOGPFAULTERRORBOX = 2
SEM_NOALIGNMENTFAULTEXCEPT = 0x8000
ctypes.windll.kernel32.SetErrorMode(
SEM_FAILCRITICALERRORS|SEM_NOGPFAULTERRORBOX|
SEM_NOALIGNMENTFAULTEXCEPT)
# TODO(maruel): Other OSes.
# - OSX, need to figure out a way to make the following process tree local:
# defaults write com.apple.CrashReporter UseUNC 1
# defaults write com.apple.CrashReporter DialogType none
# - Ubuntu, disable apport if needed.

0 comments on commit 2ac1033

Please sign in to comment.