def _pydev_attach():
    import threading
    import time
    import glob

    try:
        import pydevd
        import pydevd_tracing
    except ImportError:
        # look for a PyDev src folder
        program_files = os.environ.get("PROGRAMFILES", r"C:\Program Files (x86)")
        pattern = r"%s\Eclipse\plugins\org.python.pydev.debug_*\pysrc" % program_files
        folders = sorted(glob.glob(pattern), reverse=True)
        if folders:
            if folders[0] not in sys.path:
                sys.path.append(folders[0])

        # try to import again
        import pydevd
        import pydevd_tracing

    if not _ipython_active():
        # remove any redirection
        if getattr(sys, "_pydev_orig_stdout", None) is None:
            sys._pydev_orig_stdout = sys.stdout
        if getattr(sys, "_pydev_orig_stderr", None) is None:
            sys._pydev_orig_stderr = sys.stderr

        sys.stdout = sys._pydev_orig_stdout
        sys.stderr = sys._pydev_orig_stderr

    # stop any existing debugger
    dbg = pydevd.GetGlobalDebugger()
    if dbg:
        dbg.FinishDebuggingSession()
        time.sleep(0.1)
        pydevd_tracing.SetTrace(None)

        # remove any additional info for the current thread
        try:
            del threading.currentThread().__dict__["additionalInfo"]
        except KeyError:
            pass

        pydevd.SetGlobalDebugger(None)
        pydevd.connected = False
        time.sleep(0.1)

    # do this a couple of times as when re-connecting the first doesn't work
    _logger.info("Attempting to attach to the pydev debugger")
    if not ipython_active():
        pydevd.settrace(stdoutToServer=True, stderrToServer=True, suspend=False)
        pydevd.settrace(stdoutToServer=True, stderrToServer=True, suspend=False)
    else:
        pydevd.settrace(stdoutToServer=False, stderrToServer=False, suspend=False)
        pydevd.settrace(stdoutToServer=False, stderrToServer=False, suspend=False)
    _logger.info("Attached to PyDev")
attempt to connect or re-connect to the pydev debugger
dataset/ETHPy150Open manahl/mdf/mdf/viewer/frame.py/_pydev_attach