From: Tom Christie Date: Sun, 5 May 2019 18:58:26 +0000 (+0100) Subject: Wrap `loop.run_in_executor` up in `asyncio.ensure_future` for reliable cross-platform... X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/e6ddb68c786256e1cb0c76b42d10c212ef34cb2a Wrap `loop.run_in_executor` up in `asyncio.ensure_future` for reliable cross-platform berhavior. (#679) Closes #494 Task completion should also remove the task from `pending`. Only replicates on some platforms. (eg. Can replicate on Python 3.7+, with either Windows or whatever default Linux distro Travis uses.) --- diff --git a/black.py b/black.py index 90aaf38..dd6e372 100644 --- a/black.py +++ b/black.py @@ -526,12 +526,14 @@ async def schedule_formatting( manager = Manager() lock = manager.Lock() tasks = { - loop.run_in_executor( - executor, format_file_in_place, src, fast, mode, write_back, lock + asyncio.ensure_future( + loop.run_in_executor( + executor, format_file_in_place, src, fast, mode, write_back, lock + ) ): src for src in sorted(sources) } - pending: Iterable[asyncio.Task] = tasks.keys() + pending: Iterable[asyncio.Future] = tasks.keys() try: loop.add_signal_handler(signal.SIGINT, cancel, pending) loop.add_signal_handler(signal.SIGTERM, cancel, pending)