Skip to content

Commit

Permalink
Assign s None instead of True
Browse files Browse the repository at this point in the history
This works better if we want to type `s` as `set`. Also this is a more
typical default value when initializing a variable unlike `True`.
  • Loading branch information
jakirkham committed Dec 8, 2020
1 parent 19fdc08 commit ac0ebfe
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions distributed/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2226,7 +2226,7 @@ async def add_worker(
recommendations = {}
for ts in list(self.unrunnable):
valid = self.valid_workers(ts)
if valid is True or ws in valid:
if valid is None or ws in valid:
recommendations[ts._key] = "waiting"

if recommendations:
Expand Down Expand Up @@ -4657,7 +4657,7 @@ def decide_worker(self, ts: TaskState):
"""
valid_workers = self.valid_workers(ts)

if not valid_workers and not ts._loose_restrictions and self.workers:
if valid_workers == set() and not ts._loose_restrictions and self.workers:
self.unrunnable.add(ts)
ts.state = "no-worker"
return None
Expand Down Expand Up @@ -5518,14 +5518,14 @@ def check_idle_saturated(self, ws: WorkerState, occ: double = -1.0):
def valid_workers(self, ts: TaskState):
"""Return set of currently valid workers for key
If all workers are valid then this returns ``True``.
If all workers are valid then this returns ``None``.
This checks tracks the following state:
* worker_restrictions
* host_restrictions
* resource_restrictions
"""
s = True
s = None

if ts._worker_restrictions:
s = {w for w in ts._worker_restrictions if w in self.workers}
Expand All @@ -5539,7 +5539,7 @@ def valid_workers(self, ts: TaskState):
self.host_info[h]["addresses"] for h in hr if h in self.host_info
]
ss: set = set.union(*sl) if sl else set()
if s is True:
if s is None:
s = ss
else:
s |= ss
Expand All @@ -5555,12 +5555,12 @@ def valid_workers(self, ts: TaskState):
}

ww: set = set.intersection(*dw.values())
if s is True:
if s is None:
s = ww
else:
s &= ww

if s is True:
if s is None:
return s
else:
return {self.workers[w] for w in s}
Expand Down

0 comments on commit ac0ebfe

Please sign in to comment.