import multiprocessing
from typing import Callable
from typing import Iterable
from typing import Optional

consumer: Optional[Callable] = None


def init_fun(consumer_supplier):
    global consumer  # pylint: disable=global-statement
    consumer = consumer_supplier()


def worker_fun(datum):
    global consumer  # pylint: disable=global-statement
    consumer(datum)


def pool_consume(data: Iterable, consumer_supplier, num_processes=4, chunksize=1):
    with multiprocessing.Pool(
        processes=num_processes, initializer=init_fun, initargs=(consumer_supplier,)
    ) as pool:
        list(pool.imap_unordered(worker_fun, data, chunksize=chunksize))

import multiprocessing
from typing import Callable
from typing import Iterable
from typing import Optional

consumer: Optional[Callable] = None


def init_fun(consumer_supplier):
    global consumer  # pylint: disable=global-statement
    consumer = consumer_supplier()


def worker_fun(datum):
    global consumer  # pylint: disable=global-statement
    consumer(datum)


def pool_consume(data: Iterable, consumer_supplier, num_processes=4, chunksize=1):
    with multiprocessing.Pool(
        processes=num_processes, initializer=init_fun, initargs=(consumer_supplier,)
    ) as pool:
        list(pool.imap_unordered(worker_fun, data, chunksize=chunksize))

# pylint: disable=global-statement # pylint: disable=global-statement