nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.22k stars 1.46k forks source link

Deadloop in Windows, `os.sleep(-1)` #23733

Closed litlighilit closed 1 week ago

litlighilit commented 1 week ago

Description

when defined(windows):
  import std/os
  sleep(-1)  # <- deadloop

BTW, on POSIX, it just returns immediately, as sleep calls nanosleep, which exits with errno set as EINVAL for negative values.

Nim Version

At least from 1.6.14 to 2.1.1 and devel

Current Output

No response

Expected Output

No response

Possible Solution

Two direction:

  1. raises a exception on all platforms when milsecs is negative.
  2. add check in Windows, returns immediately for negative values

Additional Information

In Python, time.sleep raises ValueError on negative value.

Maybe we can raises OSError as Nim's sleep is in std/os

litlighilit commented 1 week ago

a mistaking duplicate of 23722,