Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for as_completed for loops in Python 2 #2071

Merged
merged 1 commit into from
Jun 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion distributed/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
from .utils_comm import (WrappedKey, unpack_remotedata, pack_data,
scatter_to_workers, gather_from_workers)
from .cfexecutor import ClientExecutor
from .compatibility import Queue as pyQueue, Empty, isqueue, html_escape
from .compatibility import (Queue as pyQueue, Empty, isqueue, html_escape,
StopAsyncIteration)
from .core import connect, rpc, clean_exception, CommClosedError, PooledRPCCall
from .metrics import time
from .node import Node
Expand Down
3 changes: 3 additions & 0 deletions distributed/compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
PY3 = False
ConnectionRefusedError = OSError
FileExistsError = OSError
class StopAsyncIteration(Exception):
pass

import gzip

Expand Down Expand Up @@ -71,6 +73,7 @@ def iscoroutinefunction(func):
from gzip import compress as gzip_compress
ConnectionRefusedError = ConnectionRefusedError
FileExistsError = FileExistsError
StopAsyncIteration = StopAsyncIteration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be causing a test failure in Dask on Python 3.4 as StopAsyncIteration was not defined until Python 3.5.

ref: https://travis-ci.org/dask/dask/jobs/396392846
ref: https://www.python.org/dev/peps/pep-0492/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dask.distributed doesn't support Python 3.4. We might consider solving this on the dask side by avoiding distributed tests somehow


def isqueue(o):
return isinstance(o, Queue)
Expand Down
20 changes: 18 additions & 2 deletions distributed/tests/test_as_completed.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

from distributed import Client
from distributed.client import _as_completed, as_completed, _first_completed
from distributed.compatibility import Empty
from distributed.compatibility import Empty, StopAsyncIteration, Queue
from distributed.utils_test import cluster, gen_cluster, inc
from distributed.utils_test import loop # noqa: F401
from distributed.compatibility import Queue


@gen_cluster(client=True)
Expand Down Expand Up @@ -152,3 +151,20 @@ def _():
result = list(ac)

assert result == [x]


@gen_cluster(client=True)
def test_async_for_py2_equivalent(c, s, a, b):
futures = c.map(sleep, [0.01] * 3, pure=False)
seq = as_completed(futures)
x = yield seq.__anext__()
y = yield seq.__anext__()
z = yield seq.__anext__()

assert x.done()
assert y.done()
assert z.done()
assert x.key != y.key

with pytest.raises(StopAsyncIteration):
yield seq.__anext__()