MCPcopy Index your code
hub / github.com/RustPython/RustPython / future_add_to_awaited_by

Function future_add_to_awaited_by

Lib/asyncio/futures.py:428–453  ·  view source on GitHub ↗

Record that `fut` is awaited on by `waiter`.

(fut, waiter, /)

Source from the content-addressed store, hash-verified

426
427
428def future_add_to_awaited_by(fut, waiter, /):
429 """Record that `fut` is awaited on by `waiter`."""
430 # For the sake of keeping the implementation minimal and assuming
431 # that most of asyncio users use the built-in Futures and Tasks
432 # (or their subclasses), we only support native Future objects
433 # and their subclasses.
434 #
435 # Longer version: tracking requires storing the caller-callee
436 # dependency somewhere. One obvious choice is to store that
437 # information right in the future itself in a dedicated attribute.
438 # This means that we'd have to require all duck-type compatible
439 # futures to implement a specific attribute used by asyncio for
440 # the book keeping. Another solution would be to store that in
441 # a global dictionary. The downside here is that that would create
442 # strong references and any scenario where the "add" call isn't
443 # followed by a "discard" call would lead to a memory leak.
444 # Using WeakDict would resolve that issue, but would complicate
445 # the C code (_asynciomodule.c). The bottom line here is that
446 # it's not clear that all this work would be worth the effort.
447 #
448 # Note that there's an accelerated version of this function
449 # shadowing this implementation later in this file.
450 if isinstance(fut, _PyFuture) and isinstance(waiter, _PyFuture):
451 if fut._Future__asyncio_awaited_by is None:
452 fut._Future__asyncio_awaited_by = set()
453 fut._Future__asyncio_awaited_by.add(waiter)
454
455
456def future_discard_from_awaited_by(fut, waiter, /):

Callers

nothing calls this directly

Calls 3

isinstanceFunction · 0.85
setFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected