From f17b17d02aa82230a2e4300534fa5d5c5c8243ad Mon Sep 17 00:00:00 2001 From: Olivier Date: Sun, 8 Nov 2020 19:52:58 +0000 Subject: [PATCH] Handle awaitables on sous to avoid warnings --- scone/sous/__main__.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scone/sous/__main__.py b/scone/sous/__main__.py index 4904798..e2b227e 100644 --- a/scone/sous/__main__.py +++ b/scone/sous/__main__.py @@ -16,10 +16,12 @@ # along with Scone. If not, see . import asyncio +import itertools import logging import os import pwd import sys +from itertools import filterfalse from pathlib import Path from typing import List, cast @@ -76,6 +78,8 @@ async def main(args: List[str]): logger.info("Worktop dir is: %s", worktop.dir) + awaitables = [] + while True: try: message = await root.recv() @@ -94,7 +98,7 @@ async def main(args: List[str]): logger.debug("going to sched task with %r", utensil) - asyncio.create_task(run_utensil(utensil, channel, worktop)) + awaitables.append(asyncio.create_task(run_utensil(utensil, channel, worktop))) elif "lost" in message: # for a then-non-existent channel, but probably just waiting on us # retry without a default route. @@ -102,6 +106,14 @@ async def main(args: List[str]): else: raise RuntimeError(f"Unknown ch0 message {message}") + for done_aw in filter(lambda aw: aw.done(), awaitables): + await done_aw + + awaitables = list(filterfalse(lambda aw: aw.done(), awaitables)) + + for aw in awaitables: + await aw + async def run_utensil(utensil: Utensil, channel: Channel, worktop: Worktop): try: