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.)
This commit is contained in:
Tom Christie 2019-05-05 19:58:26 +01:00 committed by Jelle Zijlstra
parent 4a953b7241
commit e6ddb68c78

View File

@ -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)