noxdafox / pebble

Multi threading and processing eye-candy.
GNU Lesser General Public License v3.0
525 stars 49 forks source link

Support dill #103

Closed noxdafox closed 2 years ago

noxdafox commented 2 years ago

Allow to pickle more objects by supporting dill and multiprocess.

noxdafox commented 2 years ago

Issue resolved with release 5.0.0.

ddelange commented 1 year ago

Hi @noxdafox 👋

I see that my long running processes are dying after some time using pathos.ProcessPool.imap directly, so I'd like to use your awesome max_tasks kwarg and get some fresh processes every now and then.

Two related questions arise:

ddelange commented 1 year ago

got it:

import multiprocess
from pebble import ProcessPool

MAX_WORKER_TASKS = 42
START_METHOD = "spawn"

def imap(fn, it):
    with ProcessPool(
        n_workers,
        max_tasks=MAX_WORKER_TASKS,  # restart after some time to avoid zombies
        context=multiprocess.get_context(START_METHOD),
    ) as pool:
        yield from pool.map(fn, it).result()