def select_workers_to_close(scheduler, n_to_close):
workers = list(scheduler.workers.values())<EOL>assert n_to_close <= len(workers)<EOL>key = lambda ws: ws.metrics['<STR_LIT>']<EOL>to_close = set(sorted(scheduler.idle, key=key)[:n_to_close])<EOL>if len(to_close) < n_to_close:<EOL><INDENT>rest = sorted(workers, key=key, reverse=True)<EOL>while len(to_close) < n_to_close:<EOL><INDENT>to_close.add(rest.pop())<EOL><DEDENT><DEDENT>return [ws.address for ws in to_close]<EOL>
Select n workers to close from scheduler