async def debug_start(call: ServiceCall | None = None, *, wait: bool = True) -> None: """Start the debugger.""" debugpy.listen((conf[CONF_HOST], conf[CONF_PORT])) wait = conf[CONF_WAIT] if wait: _LOGGER.warning( "Waiting for remote debug connection on %s:%s", conf[CONF_HOST], conf[CONF_PORT], ) ready = Event() def waitfor(): debugpy.wait_for_client() opp.loop.call_soon_threadsafe(ready.set) Thread(target=waitfor).start() await ready.wait() else: _LOGGER.warning( "Listening for remote debug connection on %s:%s", conf[CONF_HOST], conf[CONF_PORT], )
def main(): frontend = "192.168.0.179" parser = argparse.ArgumentParser(prog="my_megazord_program") parser.add_argument( "-f", "--frontend", help='start with localshit -f "172.17.0.2" to add frontend') parser.add_argument( "-d", "--debug", help="start localhost and wait for VS Code debugger", action="store_true", ) args = parser.parse_args() if args.frontend: frontend = args.frontend if args.debug: import debugpy debugpy.listen(5678) print("Waiting for debugger attach: %s" % os.getpid()) debugpy.wait_for_client() logging.info("Frontend server is set to %s" % frontend) try: logging.info("starting manager...") _ = LocalsHitManager(frontend=frontend) except Exception as e: logging.error("Error while starting app: %s" % e) traceback.print_exc()
def cli(ctx, config_file=None, **kwargs): """A CLI for the ramses_rf library.""" # if ctx.invoked_subcommand is None: # pass if 0 < kwargs[DEBUG_MODE] < 3: import debugpy debugpy.listen(address=(DEBUG_ADDR, DEBUG_PORT)) print( f"Debugging is enabled, listening on: {DEBUG_ADDR}:{DEBUG_PORT}.") if kwargs[DEBUG_MODE] == 1: print(" - execution paused, waiting for debugger to attach...") debugpy.wait_for_client() print(" - debugger is now attached, continuing execution.") lib_kwargs, cli_kwargs = _proc_kwargs(({CONFIG: {}}, {}), kwargs) if config_file: lib_kwargs.update(json.load(config_file)) lib_kwargs[DEBUG_MODE] = cli_kwargs[DEBUG_MODE] > 1 lib_kwargs[CONFIG][REDUCE_PROCESSING] = kwargs[REDUCE_PROCESSING] lib_kwargs[CONFIG][ENABLE_EAVESDROP] = bool(cli_kwargs.pop("eavesdrop")) ctx.obj = lib_kwargs, kwargs
def create_app(app_config): if 'REMOTE_DEBUG' in os.environ: print("Starting remote debugger on port 5678") import debugpy import logging debugpy.listen(("0.0.0.0", 5678)) print("Waiting for connection...") debugpy.wait_for_client() logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG) app = Flask(__name__) # Get flask config from object app.config.from_object(app_config) # Initalise Database db.init_app(app) # Initalise Jinija2 Filters app_filters(app) # Register blueprint app.register_blueprint(blueprint_app) # Add flask_bootstrap Bootstrap(app) # Cors cors(app) return app
def execute(self, context): #get debugpy and import if exists prefs = bpy.context.preferences.addons[__name__].preferences debugpy_path = prefs.path.rstrip("/") debugpy_port = prefs.port #actually check debugpy is still available if debugpy_path == "debugpy not found": self.report({"ERROR"}, "Couldn't detect debugpy, please specify the path manually in the addon preferences or reload the addon if you installed debugpy after enabling it.") return {"CANCELLED"} if not os.path.exists(os.path.abspath(debugpy_path+"/debugpy")): self.report({"ERROR"}, "Can't find debugpy at: %r/debugpy." % debugpy_path) return {"CANCELLED"} if not any(debugpy_path in p for p in sys.path): sys.path.append(debugpy_path) global debugpy #so we can do check later import debugpy # can only be attached once, no way to detach (at least not that I understand?) try: debugpy.listen(("localhost", debugpy_port)) except: print("Server already running.") # call our confirmation listener bpy.ops.debug.check_for_debugger() return {"FINISHED"}
def code_to_debug(): import debuggee import debugpy import sys import time from debuggee import backchannel, scratchpad debuggee.setup() _, host, port, wait_for_client, is_client_connected, stop_method = sys.argv port = int(port) debugpy.listen(address=(host, port)) if wait_for_client: backchannel.send("wait_for_client") debugpy.wait_for_client() if is_client_connected: backchannel.send("is_client_connected") while not debugpy.is_client_connected(): print("looping until is_client_connected()") time.sleep(0.1) if stop_method == "breakpoint": backchannel.send("breakpoint?") assert backchannel.receive() == "proceed" debugpy.breakpoint() print("break") # @breakpoint else: scratchpad["paused"] = False backchannel.send("loop?") assert backchannel.receive() == "proceed" while not scratchpad["paused"]: print("looping until paused") time.sleep(0.1)
def create_app(app_config): if 'REMOTE_DEBUG' in os.environ: import debugpy debugpy.listen(("0.0.0.0", 5678)) debugpy.wait_for_client() #app = Flask(__name__, static_folder='static') app = Flask(__name__) # Get flask config from object app.config.from_object(app_config) # Initalise Database db.init_app(app) # Initalise Jinija2 Filters app_filters(app) # Register blueprint app.register_blueprint(blueprint_app) # Add flask_bootstrap Bootstrap(app) # Cors cors(app) return app
def set(flag: bool=False, wait_for_client=False, host='localhost', port=8765): global _DEBUG _DEBUG = flag try: # To prevent debugpy loading again and again because of # Streamlit's execution model, we need to track debugging state if 'debugging' not in st.session_state: st.session_state.debugging = False if _DEBUG and not st.session_state.debugging: # https://code.visualstudio.com/docs/python/debugging import debugpy if not debugpy.is_client_connected(): debugpy.listen((host, port)) if wait_for_client: logging.info(f'>>> Waiting for debug client attach... <<<') debugpy.wait_for_client() # Only include this line if you always want to manually attach the debugger logging.info(f'>>> ...attached! <<<') # debugpy.breakpoint() st.session_state.debugging = True logging.info(f'>>> Remote debugging activated (host={host}, port={port}) <<<') if not _DEBUG: logging.info(f'>>> Remote debugging in NOT active <<<') st.session_state.debugging = False except: # Ignore... e.g. for cloud deployments pass
async def debug_start(call: ServiceCall | None = None, *, wait: bool = True) -> None: """Enable asyncio debugging and start the debugger.""" get_running_loop().set_debug(True) debugpy.listen((conf[CONF_HOST], conf[CONF_PORT])) if conf[CONF_WAIT]: _LOGGER.warning( "Waiting for remote debug connection on %s:%s", conf[CONF_HOST], conf[CONF_PORT], ) ready = Event() def waitfor(): debugpy.wait_for_client() hass.loop.call_soon_threadsafe(ready.set) Thread(target=waitfor).start() await ready.wait() else: _LOGGER.warning( "Listening for remote debug connection on %s:%s", conf[CONF_HOST], conf[CONF_PORT], )
def run_debugger(): import debugpy # 5678 is the default attach port in the VS Code debug configurations. Unless a host and port are specified, host defaults to 127.0.0.1 debugpy.listen(5678) print("Waiting for debugger attach") debugpy.wait_for_client() # debugpy.breakpoint() print('break on this line')
def __init__(self): if 'REMOTE_DEBUG' in os.environ: import debugpy debugpy.listen(("0.0.0.0", 5678)) debugpy.wait_for_client() self.config = Config().config self.db = Database()
def wait_for_debugger_attached(): """ Waits until a debugger on VSCode's default port is connected and then continues execution """ import debugpy # 5678 is the default attach port in the VS Code debug configurations. # Unless a host and port are specified, host defaults to 127.0.0.1 debugpy.listen(5678) print("Waiting for debugger attach") debugpy.wait_for_client()
def debug(): # pragma: no cover debugpy.listen(("0.0.0.0", 10001)) print( "⏳ VS Code debugger can now be attached, press F5 in VS Code ⏳", flush=True, ) debugpy.wait_for_client() print("🎉 VS Code debugger attached, enjoy debugging 🎉", flush=True)
def pytest_sessionstart(session): if not debugpy: return if session.config.getoption("debugger"): port = session.config.getoption("debugger_port") debugpy.listen(port) debugpy.wait_for_client()
def debug_based_on_env(): if getenv("PY_DEBUG") == "1": import multiprocessing if multiprocessing.current_process().pid > 1: import debugpy debugpy.listen(("0.0.0.0", 5678)) print("Waiting for debugging client", flush=True) debugpy.wait_for_client()
def initialize_debugger_if_needed(): if getenv("DEBUGGER") == "True": import debugpy debugpy.listen(("0.0.0.0", 5678)) print("⏳ VS Code debugger can now be attached, press F5 in VS Code ⏳", flush=True) debugpy.wait_for_client() print("🎉 VS Code debugger attached, enjoy debugging 🎉", flush=True)
def wait_for_attach(): PORT = 3001 Debug('Waiting for debugger to attach to port %i...' % PORT) # import ptvsd # ptvsd.enable_attach(address=('127.0.0.1', PORT)) #, redirect_output=True) # ptvsd.wait_for_attach() import debugpy debugpy.listen(PORT) debugpy.wait_for_client()
def start_debug_server(): while True: port = get_random_port() try: debugpy.listen(("localhost", port)) break except OSError: pass return port
def start_debug_server(): if settings.LOGGING: tmp_path = tempfile.gettempdir() debugpy.log_to(tmp_path) print(f"[IDACode] Logging to {tmp_path} with pattern debugpy.*.log") debugpy.listen((settings.HOST, settings.DEBUG_PORT)) print( f"[IDACode] IDACode debug server listening on {settings.HOST}:{settings.DEBUG_PORT}" )
def __init__(self): self.config = Config().config self.gcloud = False self.debug = False if 'REMOTE_DEBUG' in os.environ: import debugpy self.debug = True debugpy.listen(("0.0.0.0", 5678)) debugpy.wait_for_client()
def start_debug_for_vscode() -> None: """VSCodeのデバッガーをアタッチ可能なアプリケーションサーバを起動します""" import debugpy import uvicorn # デバッガーがアタッチされるまで待機してからアプリケーションを起動する debugpy.listen(("0.0.0.0", 5678)) debugpy.wait_for_client() uvicorn.run("src.api:app", host="0.0.0.0", port=8080, reload=True)
def debugpy_init(port=5678): if get_environment() == "development": import debugpy print("running in debug mode") try: debugpy.listen(("0.0.0.0", port)) debugpy.wait_for_client() except Exception: print(f"debugpy attach on port {port} aborted")
def start_debug_server(): if settings.LOGGING: tmp_path = tempfile.gettempdir() debugpy.log_to(tmp_path) print("[IDACode] Logging to {} with pattern debugpy.*.log".format( tmp_path)) debugpy.listen((settings.HOST, settings.DEBUG_PORT)) print( "[IDACode] IDACode debug server listening on {address}:{port}".format( address=settings.HOST, port=settings.DEBUG_PORT))
def initialize_flask_server_debugger_if_needed(): print('*** ***') if getenv("FLASK_DEBUG") == "True": import debugpy debugpy.listen(("0.0.0.0", 5713)) print("⏳ VS Code debugger can now be attached, press F5 in VS Code ⏳", flush=True) debugpy.wait_for_client() print("🎉 VS Code debugger attached, enjoy debugging 🎉", flush=True)
def initialize_debugger(): import multiprocessing if multiprocessing.current_process().pid > 1: import debugpy debugpy.listen(("0.0.0.0", DEBUGPORT)) print("Debugger is ready to be attached, press F5", flush=True) debugpy.wait_for_client() print("Visual Studio Code debugger is now attached", flush=True)
def initialize_flask_server_debugger_if_needed(): if getenv("DEBUGGER") == "True": import multiprocessing if multiprocessing.current_process().pid > 1: import debugpy debugpy.listen(("0.0.0.0", 4001)) print("⏳ VS Code debugger can now be attached, press F5 in VS Code ⏳", flush=True) debugpy.wait_for_client() print("🎉 VS Code debugger attached, enjoy debugging 🎉", flush=True)
def start_remote_debug(): """ Start remote debugging from level 2 and wait on it from level 3""" runtime_system = RuntimeSystem() if config.DEBUG_LEVEL > 1 and runtime_system.is_target_system: import debugpy # pylint: disable=import-outside-toplevel port = 3003 debugpy.listen(("0.0.0.0", port)) if config.DEBUG_LEVEL > 2: print("Waiting to attach on port %s", port) debugpy.wait_for_client( ) # blocks execution until client is attached
def main(): if 'REMOTE_DEBUG' in os.environ: print("Starting remote debugger on port 5678") import debugpy debugpy.listen(("0.0.0.0", 5678)) print("Waiting for connection...") debugpy.wait_for_client() args = docopt(__doc__, version='fcreplay 0.9.1') # Setup logging if not checking or generating config if not args['config']: fclogging.setup_logger() if args['tasker']: if args['start']: if args['recorder']: if '--max_instances' in args: Tasker().recorder(max_instances=args['--max_instances']) else: Tasker().recorder() if args['check_top_weekly']: Tasker().check_top_weekly() if args['check_video_status']: Tasker().check_video_status() elif args['cli']: c = Cli() sys.exit(c.cmdloop()) elif args['config']: if args['validate']: Config().validate_config_file(args['<config.json>']) if args['generate']: Config().generate_config() elif args['get']: if args['game']: Getreplay().get_game_replays(game=args['<gameid>']) if args['ranked']: Getreplay().get_ranked_replays(game=args['<gameid>'], username=args['--playerid'], pages=args['--pages']) if args['replay']: Getreplay().get_replay(url=args['<url>'], player_requested=args['--playerrequested']) if args['weekly']: Getreplay().get_top_weekly() elif args['instance']: i = Instance() i.debug = args['--debug'] i.main()
def init_debugger(): import multiprocessing if multiprocessing.current_process().pid > 1: import debugpy debugpy.listen(("0.0.0.0", 10000)) print("⏳ VS Code debugger can now be attached, press F5 in VS Code ⏳", flush=True) debugpy.wait_for_client() print("🎉 VS Code debugger attached 🎉")
def debugpy_start(): #if getenv("DEBUGGER") == "True": if 1==1: import multiprocessing if multiprocessing.current_process().pid > 1: import debugpy debugpy.listen(("0.0.0.0", 5678)) print("⏳ VS Code debugger can now be attached, press F5 in VS Code ⏳", flush=True) debugpy.wait_for_client() print("🎉 VS Code debugger attached, enjoy debugging 🎉", flush=True)