예제 #1
0
def check():
    with pydev_log.log_context(3, sys.stderr):
        assert hasattr(sys, 'gettotalrefcount')
        import pydevd_tracing

        proceed1 = threading.Event()
        proceed2 = threading.Event()

        class SomeThread(threading.Thread):
            def run(self):
                proceed1.set()
                proceed2.wait()

        t = SomeThread()
        t.start()
        proceed1.wait()
        try:

            def some_func(frame, event, arg):
                return some_func

            pydevd_tracing.set_trace_to_threads(some_func)
        finally:
            proceed2.set()

        lib = pydevd_tracing._load_python_helper_lib()
        assert lib is None
        print('Finished OK')
예제 #2
0
def test_tracing_other_threads():
    import pydevd_tracing
    import time

    def method(i):
        while True:
            trace_func = sys.gettrace()
            if trace_func:
                threading.current_thread().trace_func = trace_func
                break
            time.sleep(.01)

    threads = []
    for i in range(10):
        threads.append(threading.Thread(target=method, args=(i,)))

    def tracing_func(frame, event, args):
        return tracing_func

    for t in threads:
        t.start()

    assert pydevd_tracing.set_trace_to_threads(tracing_func, threads) == 0

    for t in threads:
        t.join(5)
        assert t.trace_func == tracing_func
예제 #3
0
def _check_tracing_other_threads():
    import pydevd_tracing
    import time
    from tests_python.debugger_unittest import wait_for_condition
    try:
        import _thread
    except ImportError:
        import thread as _thread

    # This method is called in a subprocess, so, make sure we exit properly even if we somehow
    # deadlock somewhere else.
    def dump_threads_and_kill_on_timeout():
        time.sleep(10)
        from _pydevd_bundle import pydevd_utils
        pydevd_utils.dump_threads()
        time.sleep(1)
        import os
        os._exit(77)

    _thread.start_new_thread(dump_threads_and_kill_on_timeout, ())

    def method():
        while True:
            trace_func = sys.gettrace()
            if trace_func:
                threading.current_thread().trace_func = trace_func
                break
            time.sleep(.01)

    def dummy_thread_method():
        threads.append(threading.current_thread())
        method()

    threads = []
    threads.append(threading.Thread(target=method))
    threads[-1].daemon = True
    threads[-1].start()
    _thread.start_new_thread(dummy_thread_method, ())

    wait_for_condition(lambda: len(threads) == 2,
                       msg=lambda: 'Found threads: %s' % (threads, ))

    def tracing_func(frame, event, args):
        return tracing_func

    assert pydevd_tracing.set_trace_to_threads(tracing_func) == 0

    def check_threads_tracing_func():
        for t in threads:
            if getattr(t, 'trace_func', None) != tracing_func:
                return False
        return True

    wait_for_condition(check_threads_tracing_func)

    assert tracing_func == sys.gettrace()
예제 #4
0
def _check_basic_tracing():
    import pydevd_tracing

    # Note: run this test in a separate process so that it doesn't mess with any current tracing
    # in our current process.
    called = [0]

    def tracing_func(frame, event, args):
        called[0] = called[0] + 1
        return tracing_func

    assert pydevd_tracing.set_trace_to_threads(tracing_func) == 0

    def foo():
        pass

    foo()
    assert called[0] > 2
예제 #5
0
def _check_tracing_other_threads():
    import pydevd_tracing
    import time
    from tests_python.debugger_unittest import wait_for_condition
    try:
        import _thread
    except ImportError:
        import thread as _thread

    def method():
        while True:
            trace_func = sys.gettrace()
            if trace_func:
                threading.current_thread().trace_func = trace_func
                break
            time.sleep(.01)

    def dummy_thread_method():
        threads.append(threading.current_thread())
        method()

    threads = []
    threads.append(threading.Thread(target=method))
    threads[-1].start()
    _thread.start_new_thread(dummy_thread_method, ())

    wait_for_condition(lambda: len(threads) == 2,
                       msg=lambda: 'Found threads: %s' % (threads, ))

    def tracing_func(frame, event, args):
        return tracing_func

    assert pydevd_tracing.set_trace_to_threads(tracing_func) == 0

    def check_threads_tracing_func():
        for t in threads:
            if getattr(t, 'trace_func', None) != tracing_func:
                return False
        return True

    wait_for_condition(check_threads_tracing_func)

    assert tracing_func == sys.gettrace()