Пример #1
0
    def start(self, stop_on_exit=True, profile_children=True):
        """Start the profiler.

        :param stop_on_exit: Whether to stop the profiler and flush the profile on exit.
        :param profile_children: Whether to start a profiler in child processes.
        """

        if profile_children:
            try:
                uwsgi.check_uwsgi(self._restart_on_fork,
                                  atexit=self.stop if stop_on_exit else None)
            except uwsgi.uWSGIMasterProcess:
                # Do nothing, the start() method will be called in each worker subprocess
                return

        self._profiler.start()

        if stop_on_exit:
            atexit.register(self.stop)

        if profile_children:
            if hasattr(os, "register_at_fork"):
                os.register_at_fork(after_in_child=self._restart_on_fork)
            else:
                LOG.warning(
                    "Your Python version does not have `os.register_at_fork`. "
                    "You have to start a new Profiler after fork() manually.")
Пример #2
0
def test_register():
    def foobar():
        pass

    atexit.register(foobar)
    atexit.unregister(foobar)
    atexit.unregister(foobar)
Пример #3
0
def test_prog_unregister():
    from ddtrace.internal import atexit

    def foobar():
        print("hello")

    atexit.register(foobar)
    atexit.unregister(foobar)
Пример #4
0
def test_prog_register():
    from ddtrace.internal import atexit

    def foobar(what):
        print("hello")
        print(what)

    atexit.register(foobar, "world")
Пример #5
0
def test_prog_unregister(run_python_code_in_subprocess):
    out, err, status, pid = run_python_code_in_subprocess("""
from ddtrace.internal import atexit

def foobar():
    print("hello")

atexit.register(foobar)
atexit.unregister(foobar)
""")
    assert status == 0
    assert out == b""
    assert err == b""
Пример #6
0
def test_prog_register(run_python_code_in_subprocess):
    out, err, status, pid = run_python_code_in_subprocess("""
from ddtrace.internal import atexit

def foobar(what):
    print("hello")
    print(what)

atexit.register(foobar, "world")
""")
    assert status == 0
    assert out == b"hello\nworld\n"
    assert err == b""