Skip to content

3.15 profiling, can't use ProcessPoolExecutor.map() in a simple script #140729

@dimaqq

Description

@dimaqq

Bug report

Bug description:

# test/test_unit.py
import concurrent.futures
...

def exercise(units=11, rounds=2):
    with concurrent.futures.ProcessPoolExecutor() as executor:
        ...
            results = list(
                executor.map(
                    step,
                    [f"app/{i}" for i in range(units)],
                    [config] * units,
                    [local_app_data] * units,
                    [peers_data] * units,
                )
            )


def step(
    unit: str,
    config: Mapping[str, str | int | float | bool],
    local_app_data: Mapping[str, JSON],
    all_units_data: Mapping[ops.testing.UnitID, Mapping[str, JSON]],
) -> tuple[dict[str, JSON] | None, dict[str, JSON], str | None, str]:
    ...

if __name__ == "__main__":
    import sys

    exercise(int(sys.argv[1]), int(sys.argv[2]))
(jgol-peer) 🦐/c/j/peer (main)> sudo -E env PYTHONPATH=src python -m profiling.sampling test/test_unit.py 100 100
Profiler coordinator error: Error executing script '/code/jgol/peer/test/test_unit.py': Can't pickle <function step at 0x102b7aae0>: it's not found as __main__.step

CPython versions tested on:

3.15

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions