Every time I start a debugging process for Python code in Visual Studio 2015, I need to go through a lot of stops at several lines in Python library, which are executed before my code is loaded. For example, there are unattended breakpoints (which are not shown in interface) at line 143, 147 and 184 of site.py
def addpackage(sitedir, name, known_paths):
"""Process a .pth file within the site-packages directory:
For each line in the file, either combine it with sitedir to a path
and add that to known_paths, or execute it if it starts with 'import '.
"""
if known_paths is None:
_init_pathinfo()
reset = 1
else:
reset = 0
fullname = os.path.join(sitedir, name)
try:
f = open(fullname, "rU") # <-- Line 143
except IOError:
return
with f:
for n, line in enumerate(f): # <-- Line 147
if line.startswith("#"):
continue
try:
if line.startswith(("import ", "import\t")):
exec line
continue
line = line.rstrip()
dir, dircase = makepath(sitedir, line)
if not dircase in known_paths and os.path.exists(dir):
sys.path.append(dir)
known_paths.add(dircase)
except Exception as err:
print >>sys.stderr, "Error processing line {:d} of {}:\n".format(
n+1, fullname)
for record in traceback.format_exception(*sys.exc_info()):
for line in record.splitlines():
print >>sys.stderr, ' '+line
print >>sys.stderr, "\nRemainder of file ignored"
break
if reset:
known_paths = None
return known_paths
<... skipped ...>
def addsitedir(sitedir, known_paths=None):
"""Add 'sitedir' argument to sys.path if missing and handle .pth files in
'sitedir'"""
if known_paths is None:
known_paths = _init_pathinfo()
reset = 1
else:
reset = 0
sitedir, sitedircase = makepath(sitedir)
if not sitedircase in known_paths:
sys.path.append(sitedir) # Add path component
try:
names = os.listdir(sitedir) # <-- Line 184, here it stops for a lot of times
except os.error:
return
dotpth = os.extsep + "pth"
names = [name for name in names if name.endswith(dotpth)]
for name in sorted(names):
addpackage(sitedir, name, known_paths)
if reset:
known_paths = None
return known_paths
Also, the same thing with line 18 of genericpath.py
:
def exists(path):
"""Test whether a path exists. Returns False for broken symbolic links"""
try:
os.stat(path) # <-- Line 18, breaks here very many times
except os.error:
return False
return True
All this makes every debugging session very sloooow. How can I mask out these places so they don't stop execution any more? I use Python 2.7.10 and Visual Studio 2015 under Windows 7 x64.
Select the Debug item in the menu, then select the Delete All Breakpoints option. The keyboard shortcut Ctrl+Shift+F9 will accomplish the same.