Issue #20455: asyncio: use the same code to round a timeout than the selectors

module

Sort also imports
This commit is contained in:
Victor Stinner 2014-01-31 16:25:24 +01:00
parent 665758f804
commit f2e1768bc1
1 changed files with 9 additions and 4 deletions

View File

@ -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 @@ def wait_for_handle(self, handle, timeout=None):
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 @@ def _poll(self, timeout=None):
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: