mirror of
https://github.com/python/cpython.git
synced 2025-08-27 04:05:34 +00:00
asyncio, Tulip issue 157: Improve test_events.py, avoid run_briefly() which is
not reliable
This commit is contained in:
parent
eeeebcd816
commit
e6a537976e
2 changed files with 71 additions and 73 deletions
|
@ -21,10 +21,11 @@ try:
|
|||
except ImportError: # pragma: no cover
|
||||
ssl = None
|
||||
|
||||
from . import tasks
|
||||
from . import base_events
|
||||
from . import events
|
||||
from . import futures
|
||||
from . import selectors
|
||||
from . import tasks
|
||||
|
||||
|
||||
if sys.platform == 'win32': # pragma: no cover
|
||||
|
@ -52,18 +53,14 @@ def run_briefly(loop):
|
|||
gen.close()
|
||||
|
||||
|
||||
def run_until(loop, pred, timeout=None):
|
||||
if timeout is not None:
|
||||
deadline = time.time() + timeout
|
||||
def run_until(loop, pred, timeout=30):
|
||||
deadline = time.time() + timeout
|
||||
while not pred():
|
||||
if timeout is not None:
|
||||
timeout = deadline - time.time()
|
||||
if timeout <= 0:
|
||||
return False
|
||||
loop.run_until_complete(tasks.sleep(timeout, loop=loop))
|
||||
else:
|
||||
run_briefly(loop)
|
||||
return True
|
||||
raise futures.TimeoutError()
|
||||
loop.run_until_complete(tasks.sleep(0.001, loop=loop))
|
||||
|
||||
|
||||
def run_once(loop):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue