Skip to content

profiling.sampling run --blocking hangs and writes an empty profile on Windows #152356

Description

@heejaechang

Bug report

Bug description

On Windows, python -m profiling.sampling run ... --blocking hangs indefinitely and writes a 0-byte profile, even for a trivial script that runs in well under a second natively. The same command without --blocking works and produces a small, loadable binary profile.

Reproducer

tiny_cpu.py:

def work(n):
    total = 0
    for i in range(n):
        total += i * i
    return total

if __name__ == "__main__":
    print(work(2_000_000))

Working (no --blocking):

python -m profiling.sampling run --binary -o ok.bin --mode=cpu tiny_cpu.py

→ exits 0 in ~1s; ok.bin is ~1.4 KB (~60 samples) and replays fine.

Broken (--blocking):

python -m profiling.sampling run --binary -o blocking.bin --mode=cpu --blocking tiny_cpu.py

→ the target script's own work completes (its print output appears), but the profiler process never exits. After 25s (the script runs in <0.2s natively) it was still running and had to be killed. blocking.bin is 0 bytes, so it cannot be replayed (replay rejects it as "not a binary sampling profile").

Observed vs expected

  • Observed: on Windows, --blocking hangs (well over 100× the target's native runtime) and leaves an empty, unreplayable artifact.
  • Expected: --blocking finishes near native runtime and writes a loadable binary profile, like the non-blocking path.

CPython versions tested on

3.15.0b3 (Windows, x86_64). Please verify against current main in case this is already addressed.

Operating systems tested on

Windows

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions