Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when starting more than one asynchronous processes on Windows. #35

Open
bobeff opened this issue Jul 8, 2021 · 0 comments
Open

Comments

@bobeff
Copy link

bobeff commented Jul 8, 2021

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
bobeff added a commit to bobeff/Nim that referenced this issue Jul 8, 2021
The asynchronous process completion handler callback should be called
only once. This is achieved by passing `WT_EXECUTEONLYONCE` flag to the
`registerWaitForSingleObject` Windows API procedure.

Related to cheatfate/asynctools#35
Varriount pushed a commit to nim-lang/Nim that referenced this issue Jul 9, 2021
The asynchronous process completion handler callback should be called
only once. This is achieved by passing `WT_EXECUTEONLYONCE` flag to the
`registerWaitForSingleObject` Windows API procedure.

Related to cheatfate/asynctools#35
PMunch pushed a commit to PMunch/Nim that referenced this issue Mar 28, 2022
The asynchronous process completion handler callback should be called
only once. This is achieved by passing `WT_EXECUTEONLYONCE` flag to the
`registerWaitForSingleObject` Windows API procedure.

Related to cheatfate/asynctools#35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant