Example #1
0
def test_subpool_imap():

    from mrq.context import subpool_imap

    def iterator(n):
        for i in range(0, n):
            if i == 5:
                raise Exception("Iterator exception!")
            yield i

    def inner_func(i):
        time.sleep(1)
        print("inner_func: %s" % i)
        if i == 4:
            raise Exception("Inner exception!")
        return i * 2

    with pytest.raises(Exception):
        for res in subpool_imap(10, inner_func, iterator(10)):
            print("Got %s" % res)

    for res in subpool_imap(2, inner_func, iterator(1)):
        print("Got %s" % res)

    with pytest.raises(Exception):
        for res in subpool_imap(2, inner_func, iterator(5)):
            print("Got %s" % res)
Example #2
0
def test_subpool_imap():

    from mrq.context import subpool_imap

    def iterator(n):
        for i in range(0, n):
            if i == 5:
                raise Exception("Iterator exception!")
            yield i

    def inner_func(i):
        time.sleep(1)
        print("inner_func: %s" % i)
        if i == 4:
            raise Exception("Inner exception!")
        return i * 2

    with pytest.raises(Exception):
        for res in subpool_imap(10, inner_func, iterator(10)):
            print("Got %s" % res)

    for res in subpool_imap(2, inner_func, iterator(1)):
        print("Got %s" % res)

    with pytest.raises(Exception):
        for res in subpool_imap(2, inner_func, iterator(5)):
            print("Got %s" % res)
Example #3
0
    def run(self, params):
        self.job = get_current_job()

        if params.get("imap"):
            return subpool_map(params["pool_size"], self.inner, params["inner_params"])
        else:
            return list(subpool_imap(params["pool_size"], self.inner, params["inner_params"]))