[Python-checkins] cpython: Issue #20455: asyncio: use the same code to round a timeout than the selectors
victor.stinner
python-checkins at python.org
Fri Jan 31 16:28:07 CET 2014
http://hg.python.org/cpython/rev/3f54bc5392c3
changeset: 88854:3f54bc5392c3
user: Victor Stinner <victor.stinner at gmail.com>
date: Fri Jan 31 16:25:24 2014 +0100
summary:
Issue #20455: asyncio: use the same code to round a timeout than the selectors
module
Sort also imports
files:
Lib/asyncio/windows_events.py | 13 +++++++++----
1 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/Lib/asyncio/windows_events.py b/Lib/asyncio/windows_events.py
--- a/Lib/asyncio/windows_events.py
+++ b/Lib/asyncio/windows_events.py
@@ -1,11 +1,12 @@
"""Selector and proactor eventloops for Windows."""
+import _winapi
import errno
+import math
import socket
+import struct
import subprocess
import weakref
-import struct
-import _winapi
from . import events
from . import base_subprocess
@@ -325,7 +326,9 @@
if timeout is None:
ms = _winapi.INFINITE
else:
- ms = int(timeout * 1000 + 0.5)
+ # RegisterWaitForSingleObject() has a resolution of 1 millisecond,
+ # round away from zero to wait *at least* timeout seconds.
+ ms = math.ceil(timeout * 1e3)
# We only create ov so we can use ov.address as a key for the cache.
ov = _overlapped.Overlapped(NULL)
@@ -396,7 +399,9 @@
elif timeout < 0:
raise ValueError("negative timeout")
else:
- ms = int(timeout * 1000 + 0.5)
+ # GetQueuedCompletionStatus() has a resolution of 1 millisecond,
+ # round away from zero to wait *at least* timeout seconds.
+ ms = math.ceil(timeout * 1e3)
if ms >= INFINITE:
raise ValueError("timeout too big")
while True:
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list