Example #1
0
def enable_remote_debugging():
    try:
        import ptvsd

        if ptvsd.is_attached():
            QgsMessageLog.logMessage(
                "Remote Debug for Visual Studio is already active",
                MESSAGE_CATEGORY,
                Qgis.Info,
            )
            return
        ptvsd.enable_attach(address=("localhost", 5678))
        QgsMessageLog.logMessage(
            "dem_slicer attached remote Debug for Visual Studio on port 5678",
            MESSAGE_CATEGORY,
            Qgis.Info,
        )
    except:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        format_exception = traceback.format_exception(exc_type, exc_value,
                                                      exc_traceback)
        QgsMessageLog.logMessage(repr(format_exception[0]), MESSAGE_CATEGORY,
                                 Qgis.Critical)
        QgsMessageLog.logMessage(repr(format_exception[1]), MESSAGE_CATEGORY,
                                 Qgis.Critical)
        QgsMessageLog.logMessage(repr(format_exception[2]), MESSAGE_CATEGORY,
                                 Qgis.Critical)
Example #2
0
def _bp(wait=True):
    if not ptvsd.is_attached():
        if _attach(wait):
            ptvsd.break_into_debugger()
    else:
        if need_to_debug():
            ptvsd.break_into_debugger()
Example #3
0
    def __init__(self,
                 organization,
                 base_url,
                 date_format,
                 request_date_format=None,
                 **kwargs):
        if config.debug:
            try:
                ptvsd.enable_attach(address=('0.0.0.0', 5860))
            except:
                # attach already enabled
                pass
            if not ptvsd.is_attached():
                ptvsd.wait_for_attach()

        self.organization = organization
        # date_format is the string that specifies the date style of the target website
        if request_date_format == None:
            request_date_format = date_format

        self.jobid = kwargs['_job'] if '_job' in kwargs else None

        self.session = HttpUtils.get_session()

        self.date_format = date_format
        self.time_utils = TimeUtils(date_format)
        self.base_url = base_url
        self.identifier = re.sub(r'\W', '', base_url)
        self.event_manager = EventManager()

        formatter = logging.Formatter(
            '%(asctime)s - %(name)s - %(levelname)s - %(message)s')

        self.memory_handler = logging.handlers.MemoryHandler(0)
        self.memory_handler.setFormatter(formatter)

        self.stream_handler = logging.StreamHandler()
        self.stream_handler.setFormatter(formatter)

        self.configure_logger(self.name, self.memory_handler, logging.INFO)
        self.configure_logger(self.name, self.stream_handler, logging.INFO)
        self.configure_logger('scrapy', self.memory_handler, logging.WARNING)
        self.configure_logger('scrapy', self.stream_handler, logging.WARNING)
        self.configure_logger('twisted', self.memory_handler, logging.WARNING)
        self.configure_logger('twisted', self.stream_handler, logging.WARNING)

        start_date = datetime.now().strftime('%m-%d-%Y')
        end_date = (datetime.now() +
                    relativedelta(months=+1)).strftime('%m-%d-%Y')

        request_format_utils = TimeUtils('%m-%d-%Y')
        # When this is running for multiple days, validating if the date is in the past causes issues
        self.start_date = request_format_utils.convert_date_format(
            start_date, request_date_format, validate_past=False)
        self.end_date = request_format_utils.convert_date_format(
            end_date, request_date_format, validate_past=False)
        self.start_timestamp = request_format_utils.min_timestamp_for_day(
            start_date)
        self.end_timestamp = request_format_utils.max_timestamp_for_day(
            end_date)
def start(timeout_sec=None):
    if not ptvsd.is_attached():
        # 5678 is the default attach port in the VS Code debug configurations
        print("Waiting for debugger attach from VsCode")
        ptvsd.enable_attach(address=('localhost', 5678), redirect_output=True)
        ptvsd.wait_for_attach(timeout_sec)
    return
Example #5
0
    def handle(self, *args, **options):
        # Try to enable vscode debugger
        try:
            import ptvsd

            # We only run the ptvsd server once, on PID 1
            # Otherwise django attempts to start the server on every refresh.
            if os.getpid() != 1 and not ptvsd.is_attached():
                ptvsd.enable_attach(address=("0.0.0.0", 9000), redirect_output=True)
                print("ЁЯЦе  Remote debugger running.")
        except (ImportError, OSError) as e:
            print("тЪая╕П  Couldn't start remote debugger:", e)
        super(Command, self).handle(*args, **options)
 def isConnected(self):
     if self.isDebuggerVisualStudio():
         try:
             import ptvsd
         except ImportError:
             return False
         return ptvsd.is_attached()
     else:
         if not self.updatePydevdPath():
             return False
         try:
             import pydevd
         except ImportError:
             return False
         return pydevd.connected
Example #7
0
    def execute(self, *args, **options):
        # Try to enable vscode debugger
        try:
            import ptvsd

            if options.get(
                    "debug",
                    False) and os.getpid() != 1 and not ptvsd.is_attached():
                ptvsd.enable_attach(address=("0.0.0.0", 9001),
                                    redirect_output=True)
                print("ЁЯЦе  Remote debugger waiting for attach.")
                ptvsd.wait_for_attach()
        except (ImportError, OSError) as e:
            print("тЪая╕П  Couldn't start remote debugger:", e)

        return super().execute(*args, **options)
Example #8
0
def main():
    count = 0
    while count < 50:
        if os.getenv('PTVSD_WAIT_FOR_ATTACH', None) is not None:
            print('waiting for attach')
            ptvsd.wait_for_attach()
        elif os.getenv('PTVSD_IS_ATTACHED', None) is not None:
            print('checking is attached')
            while not ptvsd.is_attached():
                time.sleep(0.1)
        else:
            pass
        print('one')
        breakpoint()  # noqa
        time.sleep(0.5)
        print('two')
        count += 1
Example #9
0
import os
import sys
import time
import ptvsd

if os.getenv('PTVSD_ENABLE_ATTACH', None) is not None:
    ptvsd.enable_attach((sys.argv[1], sys.argv[2]))

if os.getenv('PTVSD_WAIT_FOR_ATTACH', None) is not None:
    print('waiting for attach')
    ptvsd.wait_for_attach()
elif os.getenv('PTVSD_IS_ATTACHED', None) is not None:
    print('checking is attached')
    while not ptvsd.is_attached():
        time.sleep(0.1)


def main():
    count = 0
    while count < 50:
        print(count)
        time.sleep(0.1)
        if os.getenv('PTVSD_BREAK_INTO_DEBUGGER', None) is not None:
            ptvsd.break_into_debugger()
        count += 1
    path = os.getenv('PTVSD_TARGET_FILE', None)
    if path is not None:
        with open(path, 'a') as f:
            print('HERE :)', file=f)

Example #10
0
import sys
import ptvsd

if len(sys.argv) > 1:
    open(sys.argv[1], 'w').close()

i = 0
while True:
    if ptvsd.is_attached():
        ptvsd.break_into_debugger()
        if i is None: break
    i += 1

    VSCode
    launch.json
    ...
    {
        "name": "Python: Attach",
        "type": "python",
        "request": "attach",
        "localRoot": "${workspaceRoot}",
        "remoteRoot": "/home/frak/FreeboxAPI",
        "port": 3000,
        "secret": "testDebug",
        "host": "localhost"
    },
    """
    print('Wait for debugger connexion')
    ptvsd.wait_for_attach()
    ptvsd.break_into_debugger()
    print('debug On')

print('Start')
pom = 0
pim = 0
#ptvsd.break_into_debugger()
while (ptvsd.is_attached()):
    print('.')
    pom += 1
    if ((pom % 255) == 0):
        print('Pim')
        pim += 1
Example #12
0
    def start_debugger_tracing(self, context):
        try:
            import ptvsd
            ptvsd.tracing(True)

            ptvsd.enable_attach(address=(
                "localhost",
                ConfigProvider.get(config_names.THUNDRA_LAMBDA_DEBUGGER_PORT)))
            if not self.debugger_process:
                env = os.environ.copy()
                env['BROKER_HOST'] = str(
                    ConfigProvider.get(
                        config_names.THUNDRA_LAMBDA_DEBUGGER_BROKER_HOST))
                env['BROKER_PORT'] = str(
                    ConfigProvider.get(
                        config_names.THUNDRA_LAMBDA_DEBUGGER_BROKER_PORT))
                env['DEBUGGER_PORT'] = str(
                    ConfigProvider.get(
                        config_names.THUNDRA_LAMBDA_DEBUGGER_PORT))
                env['AUTH_TOKEN'] = str(
                    ConfigProvider.get(
                        config_names.THUNDRA_LAMBDA_DEBUGGER_AUTH_TOKEN))
                env['SESSION_NAME'] = str(
                    ConfigProvider.get(
                        config_names.THUNDRA_LAMBDA_DEBUGGER_SESSION_NAME))

                if hasattr(context, 'get_remaining_time_in_millis'):
                    env['SESSION_TIMEOUT'] = str(
                        context.get_remaining_time_in_millis() +
                        int(time.time() * 1000.0))

                debug_bridge_file_path = os.path.join(
                    os.path.dirname(__file__), '../../debug/bridge.py')
                self.debugger_process = subprocess.Popen(
                    ["python", debug_bridge_file_path],
                    stdout=subprocess.PIPE,
                    stdin=subprocess.PIPE,
                    env=env)

            start_time = time.time()
            debug_process_running = True
            while time.time() < (start_time + ConfigProvider.get(config_names.THUNDRA_LAMBDA_DEBUGGER_WAIT_MAX) / 1000) \
                    and not ptvsd.is_attached():
                if self.debugger_process.poll() is None:
                    ptvsd.wait_for_attach(0.01)
                else:
                    debug_process_running = False
                    break

            if not ptvsd.is_attached():
                if debug_process_running:
                    logger.error('Couldn\'t complete debugger handshake in {} milliseconds.' \
                                 .format(ConfigProvider.get(config_names.THUNDRA_LAMBDA_DEBUGGER_WAIT_MAX)))
                ptvsd.tracing(False)
            else:
                ptvsd.tracing(True)

        except Exception as e:
            logger.error(
                "error while setting tracing true to debugger using ptvsd: {}".
                format(e))