Skip to content

Feature request: support for multiprocessing.Pool "initializer". #231

@gwerbin

Description

@gwerbin

The multiprocessing.Pool interface provides the ability to pass a custom "initializer" function to each worker: https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool.

This is useful for things like suppressing specific warnings, setting up logging, and other "scaffolding" that is occasionally useful (or even required) in applications.

It seems like Pandarallel does not use its own initializer function, so it would be nice if users could provide their own.

Looking over the code, this seems like a relatively unintrusive backward-compatible change that most users won't notice at all, but would benefit the small number of users who do want or need this feature.

Hypothetical usage:

def _suppress_shapely_warning(ignore: bool = True) -> None:
    import warnings
    warnings.filterwarnings(
        'ignore' if ignore else 'default',
        message='invalid value encountered in intersects',
        category=RuntimeWarning,
        module=r'shapely\.predicates',
        lineno=758,
        append=True,
    )

pandarallel.initialize(
    nb_workers=10,
    progress_bar=False,
    initializer=_suppress_shapely_warning,
    initargs=(True,),
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions