From e6ddb68c786256e1cb0c76b42d10c212ef34cb2a Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Sun, 5 May 2019 19:58:26 +0100 Subject: [PATCH] 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.) --- black.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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) -- 2.39.5