def func(expected_tracing): assert ptvsd.tracing() == expected_tracing, "inside func({0!r})".format( expected_tracing ) print(1) # @inner1 # Test nested change/restore. Going from False to True only works entirely # correctly on Python 3.6+; on earlier versions, if tracing wasn't enabled # when the function is entered, re-enabling it later will not cause the # breakpoints in this function to light up. However, it will allow hitting # breakpoints in functions called from here. def inner2(): print(2) # @inner2 with ptvsd.tracing(not expected_tracing): assert ptvsd.tracing() != expected_tracing, "inside with-statement" inner2() assert ptvsd.tracing() == expected_tracing, "after with-statement" print(3) # @inner3
def stop_debugger_tracing(self): try: import ptvsd ptvsd.tracing(False) from ptvsd.attach_server import debugger_attached debugger_attached.clear() except Exception as e: logger.error( "error while setting tracing false to debugger using ptvsd: {}" .format(e)) try: if self.debugger_process: o, e = self.debugger_process.communicate(b"fin\n") debug_logger("Thundra debugger process output: {}".format( o.decode("utf-8"))) self.debugger_process = None except Exception as e: self.debugger_process = None logger.error( "error while killing proxy process for debug: {}".format(e))
def code_to_debug(): from dbgimporter import import_and_enable_debugger import_and_enable_debugger() import ptvsd def func(expected_tracing): assert ptvsd.tracing() == expected_tracing, ( "inside func({0!r})".format(expected_tracing) ) print(1) # @inner1 # Test nested change/restore. Going from False to True only works entirely # correctly on Python 3.6+; on earlier versions, if tracing wasn't enabled # when the function is entered, re-enabling it later will not cause the # breakpoints in this function to light up. However, it will allow hitting # breakpoints in functions called from here. def inner2(): print(2) # @inner2 with ptvsd.tracing(not expected_tracing): assert ptvsd.tracing() != expected_tracing, "inside with-statement" inner2() assert ptvsd.tracing() == expected_tracing, "after with-statement" print(3) # @inner3 assert ptvsd.tracing(), "before tracing(False)" ptvsd.tracing(False) assert not ptvsd.tracing(), "after tracing(False)" print(0) # @outer1 func(False) ptvsd.tracing(True) assert ptvsd.tracing(), "after tracing(True)" print(0) # @outer2 func(True)
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))