1 SUSPECT #1
import re
# Catastrophic backtracking
rx = re.compile(r"(a+)+b")
rx.match("a" * 30 + "X") # (no error β but THIS HANGS for ~30 seconds.
# The fix: use re.compile with possessive quantifiers or rewrite the regex.)
# match returns None after ~28 seconds 2 SUSPECT #2
from concurrent.futures import ThreadPoolExecutor
def boom():
raise ValueError("inside thread")
with ThreadPoolExecutor() as ex:
fut = ex.submit(boom)
fut.result() Traceback (most recent call last):
File "lineup.py", line 8, in <module>
fut.result()
~~~~~~~~~~^^
concurrent.futures.process.BrokenExecutor: A child process terminated abruptly, the process pool is not usable anymore 3 SUSPECT #3
import inspect
def f(): pass
sig = inspect.signature(f)
bound = sig.bind() # no args
bound.apply_defaults()
print(bound.arguments) # (no error)
OrderedDict() 4 SUSPECT #4
from functools import singledispatch
@singledispatch
def show(x):
return f"any: {x}"
@show.register(int)
def _(x): return f"int: {x}"
print(show(True)) # (no error β bool is a subclass of int, so int dispatch wins.
# This is a footgun: True/False go through the int register.)
int: True 5 SUSPECT #5
import gc
class Node:
def __init__(self): self.next = None
a = Node(); b = Node()
a.next = b; b.next = a # cycle
del a; del b
gc.collect()
print(gc.garbage) # (no error β modern Python's cycle collector handles this)
[]