summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/catapult/common/py_utils/py_utils/atexit_with_log.py
blob: f217c09436616f52fa246ee6cf1277bb67347ce0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import atexit
import logging


def _WrapFunction(function):
  def _WrappedFn(*args, **kwargs):
    logging.debug('Try running %s', repr(function))
    try:
      function(*args, **kwargs)
      logging.debug('Did run %s', repr(function))
    except Exception:  # pylint: disable=broad-except
      logging.exception('Exception running %s', repr(function))
  return _WrappedFn


def Register(function, *args, **kwargs):
  atexit.register(_WrapFunction(function), *args, **kwargs)