Issue #12459: time.sleep() now raises a ValueError if the sleep length is
negative, instead of an infinite sleep on Windows or raising an IOError on
Linux for example, to have the same behaviour on all platforms.
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
index 9d7dbc8..94de098 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -27,6 +27,8 @@
                          int(self.t))
 
     def test_sleep(self):
+        self.assertRaises(ValueError, time.sleep, -2)
+        self.assertRaises(ValueError, time.sleep, -1)
         time.sleep(1.2)
 
     def test_strftime(self):
diff --git a/Misc/NEWS b/Misc/NEWS
index 4f41fb1..b96ca50 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -219,6 +219,10 @@
 Library
 -------
 
+- Issue #12459: time.sleep() now raises a ValueError if the sleep length is
+  negative, instead of an infinite sleep on Windows or raising an IOError on
+  Linux for example, to have the same behaviour on all platforms.
+
 - Issue #12451: pydoc: html_getfile() now uses tokenize.open() to support
   Python scripts using a encoding different than UTF-8 (read the coding cookie
   of the script).
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 636d4ad..4dc82a0 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -141,6 +141,11 @@
     double secs;
     if (!PyArg_ParseTuple(args, "d:sleep", &secs))
         return NULL;
+    if (secs < 0) {
+        PyErr_SetString(PyExc_ValueError,
+                        "sleep length must be non-negative");
+        return NULL;
+    }
     if (floatsleep(secs) != 0)
         return NULL;
     Py_INCREF(Py_None);