asynctools
asynctools copied to clipboard
Crash when starting more than one asynchronous processes on Windows.
The following simple program crashes on Windows:
import strformat, std/enumerate, os, asyncdispatch, asynctools/asyncproc
type
ProcessOutput = tuple[exitCode: int, output: string]
var urlsToDownload: seq[string] = @[
"www.w3.org/TR/html401/html40.txt",
"www.w3.org/TR/2002/REC-xhtml1-20020801/xhtml1.pdf"]
proc downloadUrl(url: string): Future[ProcessOutput] {.async.} =
return await asyncproc.execProcess(&"curl {url}")
var urlsContents: seq[Future[ProcessOutput]]
for url in urlsToDownload:
echo &"Downloading {url} ..."
urlsContents.add downloadUrl(url)
let results = waitFor all(urlsContents)
for i, result in enumerate(results):
if result.exitCode != QuitSuccess:
echo &"Error {result.exitCode}: {result.output}"
continue
let fileName = urlsToDownload[i].splitPath.tail
writeFile(fileName, result.output)
Tested with:
- asynctools Git revision:
84ced6d002789567f2396c75800ffd6dff2866f7 - nim --version
Nim Compiler Version 1.5.1 [Windows: amd64]
Compiled at 2021-07-08
Copyright (c) 2006-2021 by Andreas Rumpf
git hash: c57bd0f3eed8ff6cbfc2f806bed6e1f6b5135f5b
active boot switches: -d:release -d:danger