Exemplo n.º 1
0
 def func(x):
     with warnings.catch_warnings(record=True) as record:
         with local_client() as c:
             x = c.submit(inc, x)
             result = x.result()
         assert any("worker_client" in str(r.message) for r in record)
         return result
Exemplo n.º 2
0
    def func():
        with local_client() as ee:
            x = ee.submit(inc, 1, workers=a_address)
            y = ee.submit(inc, 2, workers=b_address)

            xx, yy = ee.gather([x, y])
        return xx, yy
Exemplo n.º 3
0
    def func():
        with local_client() as ee:
            x = ee.submit(inc, 1, workers=a_address)
            y = ee.submit(inc, 2, workers=b_address)

            xx, yy = ee.gather([x, y])
        return xx, yy
Exemplo n.º 4
0
 def func(x):
     with warnings.catch_warnings(record=True) as record:
         with local_client() as c:
             x = c.submit(inc, x)
             result = x.result()
         assert any("worker_client" in str(r.message) for r in record)
         return result
Exemplo n.º 5
0
    def produce(n):
        with local_client() as c:
            x = c.channel('x')
            for i in range(n):
                future = c.submit(slowinc, i, delay=0.01, key='f-%d' % i)
                x.append(future)

            x.flush()
Exemplo n.º 6
0
 def consume():
     with local_client() as c:
         x = c.channel('x')
         y = c.channel('y')
         last = 0
         for i, future in enumerate(x):
             last = c.submit(add, future, last, key='add-' + future.key)
             y.append(last)
Exemplo n.º 7
0
    def produce(n):
        with local_client() as c:
            x = c.channel('x')
            for i in range(n):
                future = c.submit(slowinc, i, delay=0.01, key='f-%d' % i)
                x.append(future)

            x.flush()
Exemplo n.º 8
0
    def mysum():
        result = 0
        sub_tasks = [delayed(double)(i) for i in range(100)]

        with local_client() as lc:
            futures = lc.compute(sub_tasks)
            for f in as_completed(futures):
                result += f.result()
        return result
Exemplo n.º 9
0
def fib(n):
    if n < 2:
        return n
    else:
        with local_client() as c:
            a = c.submit(fib, n - 1)
            b = c.submit(fib, n - 2)
            a, b = c.gather([a, b])
            return a + b
Exemplo n.º 10
0
    def func():
        with local_client() as c:
            correct = True
            for data in [[1, 2], (1, 2), {1, 2}]:
                futures = c.scatter(data)
                correct &= type(futures) == type(data)

            o = object()
            futures = c.scatter({'x': o})
            correct &= c.worker.data['x'] is o
            return correct
Exemplo n.º 11
0
    def func():
        with local_client() as c:
            correct = True
            for data in [[1, 2], (1, 2), {1, 2}]:
                futures = c.scatter(data)
                correct &= type(futures) == type(data)

            o = object()
            futures = c.scatter({'x': o})
            correct &= c.worker.data['x'] is o
            return correct
Exemplo n.º 12
0
    def func():
        with local_client() as c:
            futures = c.scatter([1, 2, 3, 4, 5])
            assert isinstance(futures, (list, tuple))
            assert len(futures) == 5

            x = c.worker.data.copy()
            y = {f.key: i for f, i in zip(futures, [1, 2, 3, 4, 5])}
            assert x == y

            total = c.submit(sum, futures)
            return total.result()
Exemplo n.º 13
0
    def func():
        with local_client() as c:
            futures = c.scatter([1, 2, 3, 4, 5])
            assert isinstance(futures, (list, tuple))
            assert len(futures) == 5

            x = c.worker.data.copy()
            y = {f.key: i for f, i in zip(futures, [1, 2, 3, 4, 5])}
            assert x == y

            total = c.submit(sum, futures)
            return total.result()
Exemplo n.º 14
0
 def func(x):
     with local_client() as c:
         x = c.submit(inc, x)
         y = c.submit(double, x)
         result = x.result() + y.result()
         return result
Exemplo n.º 15
0
 def func(x):
     with local_client() as c:
         x = c.submit(inc, x)
         y = c.submit(double, x)
         result = x.result() + y.result()
         return result
Exemplo n.º 16
0
 def f():
     with local_client() as lc:
         return lc.loop is lc.worker.loop