예제 #1
0
    def __call__(self):
        # We monkey-patch the thread creation so that this function is called in the new thread. At this point
        # we notify of its creation and start tracing it.
        global_debugger = get_global_debugger()

        thread_id = None
        if global_debugger is not None:
            # Note: if this is a thread from threading.py, we're too early in the boostrap process (because we mocked
            # the start_new_thread internal machinery and thread._bootstrap has not finished), so, the code below needs
            # to make sure that we use the current thread bound to the original function and not use
            # threading.currentThread() unless we're sure it's a dummy thread.
            t = getattr(self.original_func, '__self__', getattr(self.original_func, 'im_self', None))
            if not isinstance(t, threading.Thread):
                # This is not a threading.Thread but a Dummy thread (so, get it as a dummy thread using
                # currentThread).
                t = threading.currentThread()
                
            if not getattr(t, 'is_pydev_daemon_thread', False):
                thread_id = get_thread_id(t)
                global_debugger.notify_thread_created(thread_id, t)
                _on_set_trace_for_new_thread(global_debugger)
            
            if getattr(global_debugger, 'thread_analyser', None) is not None:
                try:
                    from pydevd_concurrency_analyser.pydevd_concurrency_logger import log_new_thread
                    log_new_thread(global_debugger, t)
                except:
                    sys.stderr.write("Failed to detect new thread for visualization")
        try:
            ret = self.original_func(*self.args, **self.kwargs)
        finally:
            if thread_id is not None:
                global_debugger.notify_thread_not_alive(thread_id)
        
        return ret
예제 #2
0
    def __call__(self):
        # We monkey-patch the thread creation so that this function is called in the new thread. At this point
        # we notify of its creation and start tracing it.
        global_debugger = get_global_debugger()

        thread_id = None
        if global_debugger is not None:
            # Note: if this is a thread from threading.py, we're too early in the boostrap process (because we mocked
            # the start_new_thread internal machinery and thread._bootstrap has not finished), so, the code below needs
            # to make sure that we use the current thread bound to the original function and not use
            # threading.currentThread() unless we're sure it's a dummy thread.
            t = getattr(self.original_func, '__self__', getattr(self.original_func, 'im_self', None))
            if not isinstance(t, threading.Thread):
                # This is not a threading.Thread but a Dummy thread (so, get it as a dummy thread using
                # currentThread).
                t = threading.currentThread()

            if not getattr(t, 'is_pydev_daemon_thread', False):
                thread_id = get_current_thread_id(t)
                global_debugger.notify_thread_created(thread_id, t)
                _on_set_trace_for_new_thread(global_debugger)

            if getattr(global_debugger, 'thread_analyser', None) is not None:
                try:
                    from pydevd_concurrency_analyser.pydevd_concurrency_logger import log_new_thread
                    log_new_thread(global_debugger, t)
                except:
                    sys.stderr.write("Failed to detect new thread for visualization")
        try:
            ret = self.original_func(*self.args, **self.kwargs)
        finally:
            if thread_id is not None:
                global_debugger.notify_thread_not_alive(thread_id)

        return ret
예제 #3
0
    def __call__(self):
        # We monkey-patch the thread creation so that this function is called in the new thread. At this point
        # we notify of its creation and start tracing it.
        global_debugger = get_global_debugger()

        thread_id = None
        if global_debugger is not None:
            # Note: if this is a thread from threading.py, we're too early in the boostrap process (because we mocked
            # the start_new_thread internal machinery and thread._bootstrap has not finished), so, the code below needs
            # to make sure that we use the current thread bound to the original function and not use
            # threading.currentThread() unless we're sure it's a dummy thread.
            t = getattr(self.original_func, '__self__',
                        getattr(self.original_func, 'im_self', None))
            if not isinstance(t, threading.Thread):
                # This is not a threading.Thread but a Dummy thread (so, get it as a dummy thread using
                # currentThread).
                t = threading.currentThread()

            if not getattr(t, 'is_pydev_daemon_thread', False):
                thread_id = get_current_thread_id(t)
                global_debugger.notify_thread_created(thread_id, t)
                _on_set_trace_for_new_thread(global_debugger)

            if getattr(global_debugger, 'thread_analyser', None) is not None:
                try:
                    from pydevd_concurrency_analyser.pydevd_concurrency_logger import log_new_thread
                    log_new_thread(global_debugger, t)
                except:
                    sys.stderr.write(
                        "Failed to detect new thread for visualization")
        try:
            try:
                ret = self.original_func(*self.args, **self.kwargs)
            except:
                # If threads die with the debugger alive, it's possible that we
                # have exceptions during teardown (Python goes through each module
                # and sets their attributes to None). In this situation, don't
                # report spurious exceptions because of that.
                if sys is None or pydevd_tracing is None:
                    return
        finally:
            if sys is None or pydevd_tracing is None:
                return
            else:
                if thread_id is not None and global_debugger is not None:
                    global_debugger.notify_thread_not_alive(thread_id)
                frame = sys._getframe()
                while frame is not None:
                    if frame.f_trace is not None:
                        frame.f_trace = NO_FTRACE
                    frame = frame.f_back
                pydevd_tracing.SetTrace(None)

        return ret
    def __call__(self):
        _on_set_trace_for_new_thread(self.global_debugger)
        global_debugger = self.global_debugger

        if global_debugger is not None and global_debugger.thread_analyser is not None:
            # we can detect start_new_thread only here
            try:
                from pydevd_concurrency_analyser.pydevd_concurrency_logger import log_new_thread
                log_new_thread(global_debugger)
            except:
                sys.stderr.write("Failed to detect new thread for visualization")

        return self.original_func(*self.args, **self.kwargs)
예제 #5
0
    def __call__(self):
        _on_set_trace_for_new_thread(self.global_debugger)
        global_debugger = self.global_debugger

        if global_debugger is not None and global_debugger.thread_analyser is not None:
            # we can detect start_new_thread only here
            try:
                from pydevd_concurrency_analyser.pydevd_concurrency_logger import log_new_thread
                log_new_thread(global_debugger)
            except:
                sys.stderr.write("Failed to detect new thread for visualization")

        return self.original_func(*self.args, **self.kwargs)
예제 #6
0
    def __call__(self):
        from pydevd_comm import GetGlobalDebugger
        global_debugger = GetGlobalDebugger()
        if global_debugger is not None:
            global_debugger.SetTrace(global_debugger.trace_dispatch)

        if global_debugger.thread_analyser is not None:
            # we can detect start_new_thread only here
            try:
                from pydevd_concurrency_analyser.pydevd_concurrency_logger import log_new_thread
                log_new_thread(global_debugger)
            except:
                sys.stderr.write("Failed to detect new thread for visualization")

        return self.original_func(*self.args, **self.kwargs)
예제 #7
0
    def __call__(self):
        from pydevd_comm import GetGlobalDebugger
        global_debugger = GetGlobalDebugger()
        if global_debugger is not None:
            global_debugger.SetTrace(global_debugger.trace_dispatch)

        if global_debugger.thread_analyser is not None:
            # we can detect start_new_thread only here
            try:
                from pydevd_concurrency_analyser.pydevd_concurrency_logger import log_new_thread
                log_new_thread(global_debugger)
            except:
                sys.stderr.write(
                    "Failed to detect new thread for visualization")

        return self.original_func(*self.args, **self.kwargs)