# Python's re has no such cache. The same pattern, in a child process with a
# three-second limit: 12 a's finish, 40 do not.
import subprocess
import sys

CHILD = 'import re; print(bool(re.match(r"^(a|a)*$", "a" * {n} + "b")))'

for n in (12, 40):
    try:
        done = subprocess.run(
            [sys.executable, "-c", CHILD.format(n=n)], capture_output=True, text=True, timeout=3
        )
        print(f"  {n:>2} a's and a b: finished, matched = {done.stdout.strip()}")
    except subprocess.TimeoutExpired:
        print(f"  {n:>2} a's and a b: still running after 3 s, killed")
