Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can python breakpoint() be disabled in a script (with VSCode debugger)?

I'm trying to use the new (python 3.7+) breakpoint(). During initial devlopment, I want to be able to disable all breakpoints within the script. Is this possible?

I tried setting PYTHONBREAKPOINT environmental variable to 0 at the top of the script, but the debugger still stops at each one. Does the env var have to set before the script is initialised? or does it need to be set to something else?

I'm using VSCode debugger, working in a virtual env, on windows 10.

    import os

    os.environ['PYTHONBREAKPOINT'] = "0"

    a = 1

    print(os.environ['PYTHONBREAKPOINT'])  # prints 0
    breakpoint()  # debugger still stops here

    b = 2

Edit: If i use pdb in the command line, breakpoints are disabled. So it is VSCode debugger related Edit2: Appears to be VSCode debugger specific. Accepted answer work for me, but means cannot use different dev and production environments to suppress breakpoints, have to change the code instead.

like image 575
Yobmod Avatar asked Jul 29 '26 16:07

Yobmod


1 Answers

You can just set sys.breakpointhook, a function that is called when breakpoint() is executed:

import sys

sys.breakpointhook = lambda *x: None  # function that does nothing

a = 1
breakpoint()
b = 2
like image 103
L3viathan Avatar answered Aug 01 '26 08:08

L3viathan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!