from typing import Callable


def _make_target(job) -> Callable:
    """
    Create target function that pulls an element from the queue and runs the
    job on that element.

    Args:
        job (Job): Job to run.

    Returns:
        Callable: Target to use for the multiprocessing API.
    """

    def _target(queue):
        # Lock cuda device
        cuda_device_id = queue.get()

        # Run job on this device
        job.run(cuda_device_id)

        # Free cuda device
        queue.put(cuda_device_id)

    return _target