def __init__(self, max_resources, factory):
        """Create a new MultiResource, use 'factory' to create new resources.

        Will call 'factory' at most 'max_resources' times.
        Note that 'factory' must be multiprocess-safe.

        :max_resources: integer
        :factory: a callable that returns a new resource

        """
        if max_resources < 1:
            raise ValueError(
                'max_resources should be at least 1, got {}'.format(
                    max_resources))
        self._factory = factory

        # pychecker makes us do this, it won't recognise that
        # multiprocessing.queues is a thing.
        mp = multiprocessing
        self._free_resources = mp.queues.SimpleQueue()
        for _ in xrange(max_resources):
            self._free_resources.put(_NotAResource)
dataset/ETHPy150Open bloomberg/phabricator-tools/py/phl/phlsys_multiprocessing.py/MultiResource.__init__/original