crossbario / crossbario/autobahn-python

[asyncio] The on_progress options (for progressive result) accept coroutines but do not await them.

Open
#1,172 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-discussion
Dominant language
Python
Stars
2.5k
Forks
768
PR merge metrics
No merged PRs in 30d

Description

Hello.
I noticed than using the ProgressiveResult with asyncio the on_progress option accept either a function or a coroutine, however in case of the later, they are scheduled but not awaited (or even "gathered" once they have all been scheduled.)

Here a snippet to demonstrate it:

    sender = Component(transports=config["transports"], realm=config["realm"])
    getter = Component(transports=config["transports"], realm=config["realm"])

    sender_ready = asyncio.Event()

    @sender.on_ready
    async def trigger(session: ApplicationSession, *args, **kwargs):
        sender_ready.set()

    @sender.register("foo", options=RegisterOptions(details_arg="details"))
    async def send(details: CallDetails):
        for i in range(10):
            details.progress(i)
            await asyncio.sleep(0)

    @getter.on_ready
    async def get(session: ApplicationSession, *args, **kwargs):
        await sender_ready.wait()
        
        # use a coroutine and sleep for a random amount of time.
        async def on_progress(i: int):
            await asyncio.sleep(random.randint(0,2))
            print(i, end=" ", flush=True)

        await session.call("foo", options=CallOptions(on_progress=on_progress))
        print("end", end=" ", flush=True)

    run([sender, getter], log_level="info")

One could expect to get: 0 1 2 3 4 5 6 7 8 9 end or at least all the numbers randomized, then end but end is printed first then the numbers: end. 1 2 5 8 0 3 4 6 7 9

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the asyncio ProgressiveResult handling for CallOptions(on_progress=...) and the session.call entry point. Verify how callback results are scheduled, then add coverage showing that all progress callbacks complete before the call returns, including the coroutine and delayed-callback behavior described in the report.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.