Skip to content
Open
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: 3 additions & 0 deletions distributed/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ async def test_variable(c, s, a, b):

future = c.submit(inc, 1)

assert not await x.is_set()
await x.set(future)
assert await x.is_set()
future2 = await xx.get()
assert future.key == future2.key

Expand All @@ -30,6 +32,7 @@ async def test_variable(c, s, a, b):
assert s.tasks # future still present

x.delete()
assert not await x.is_set()

start = time()
while s.tasks:
Expand Down
18 changes: 17 additions & 1 deletion distributed/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ def __init__(self, scheduler):
self.started = asyncio.Condition()

self.scheduler.handlers.update(
{"variable_set": self.set, "variable_get": self.get}
{
"variable_set": self.set,
"variable_is_set": self.is_set,
"variable_get": self.get,
}
)

self.scheduler.stream_handlers["variable-future-release"] = self.future_release
Expand All @@ -58,6 +62,9 @@ async def set(self, name=None, key=None, data=None, client=None):
self.started.notify_all()
self.variables[name] = record

async def is_set(self, comm=None, name=None, client=None):
return name in self.variables

async def release(self, key, name):
while self.waiting[key, name]:
async with self.waiting_conditions[name]:
Expand Down Expand Up @@ -189,6 +196,15 @@ def set(self, value, **kwargs):
"""
return self.client.sync(self._set, value, **kwargs)

async def _is_set(self):
return await self.client.scheduler.variable_is_set(
name=self.name, client=self.client.id
)

def is_set(self):
"""Check the variable has been set"""
return self.client.sync(self._is_set)

async def _get(self, timeout=None):
d = await self.client.scheduler.variable_get(
timeout=timeout, name=self.name, client=self.client.id
Expand Down