Skip to content

Before Python 3.7, async.wait_for can throw concurrent.futures.TimeoutError #479

@bdraco

Description

@bdraco

self = <zeroconf.asyncio.AsyncZeroconf object at 0x7f0390ba1ef0>, timeout = 50

    async def async_wait(self, timeout: float) -> None:
        """Calling task waits for a given number of milliseconds or until notified."""
        with contextlib.suppress(asyncio.TimeoutError):
            async with self.condition:
>               await asyncio.wait_for(self.condition.wait(), _millis_to_seconds(timeout))

zeroconf/asyncio.py:364: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

fut = <Task cancelled coro=<Condition.wait() done, defined at /opt/hostedtoolcache/Python/3.6.13/x64/lib/python3.6/asyncio/locks.py:325>>
timeout = 0.05

    @coroutine
    def wait_for(fut, timeout, *, loop=None):
        """Wait for the single Future or coroutine to complete, with timeout.
    
        Coroutine will be wrapped in Task.
    
        Returns result of the Future or coroutine.  When a timeout occurs,
        it cancels the task and raises TimeoutError.  To avoid the task
        cancellation, wrap it in shield().
    
        If the wait is cancelled, the task is also cancelled.
    
        This function is a coroutine.
        """
        if loop is None:
            loop = events.get_event_loop()
    
        if timeout is None:
            return (yield from fut)
    
        waiter = loop.create_future()
        timeout_handle = loop.call_later(timeout, _release_waiter, waiter)
        cb = functools.partial(_release_waiter, waiter)
    
        fut = ensure_future(fut, loop=loop)
        fut.add_done_callback(cb)
    
        try:
            # wait until the future completes or the timeout
            try:
                yield from waiter
            except futures.CancelledError:
                fut.remove_done_callback(cb)
                fut.cancel()
                raise
    
            if fut.done():
                return fut.result()
            else:
                fut.remove_done_callback(cb)
                fut.cancel()
>               raise futures.TimeoutError()
E               concurrent.futures._base.TimeoutError

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions