Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanic.event() fires when any event in the group is dispatched #2826

Closed
1 task done
talljosh opened this issue Sep 23, 2023 · 1 comment · Fixed by #2827
Closed
1 task done

Sanic.event() fires when any event in the group is dispatched #2826

talljosh opened this issue Sep 23, 2023 · 1 comment · Fixed by #2827
Labels

Comments

@talljosh
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When I wait for an event:

await app.event('myapp.something.arrived')

The event fires when another signal/event in the same event group is dispatched:

await app.dispatch('myapp.something.exploded')

This appears to be because of this section of signals.py, which calls set() on every event in the event group.

This is unexpected behaviour. If I wait for a particular event, I don't expect the future to return until that particular event is dispatched.

Code snippet

import asyncio
from sanic import Sanic
from sanic.response import text

app = Sanic('example')
app.config.EVENT_AUTOREGISTER = True


@app.get('/')
async def example(request):
    task = asyncio.create_task(app.event('foo.bar.baz'))

    await app.dispatch('foo.bar.spam')

    await asyncio.sleep(.5)
    assert not task.done()

    return text('ok')

Expected Behavior

I do not expect this code to raise an AssertionError, but it does.

How do you run Sanic?

Sanic CLI

Operating System

Linux

Sanic Version

23.3.0

Additional context

No response

@talljosh talljosh added the bug label Sep 23, 2023
talljosh added a commit to talljosh/sanic that referenced this issue Sep 23, 2023
@talljosh
Copy link
Contributor Author

I'm working on a potential fix for this in https://github.com/talljosh/sanic. I've done a basic fix, but I'd like to update it to allow app.event() to take condition and exclusive args in the same way signal handlers can.

talljosh added a commit to talljosh/sanic that referenced this issue Sep 24, 2023
talljosh added a commit to talljosh/sanic that referenced this issue Sep 24, 2023
talljosh added a commit to talljosh/sanic that referenced this issue Sep 25, 2023
…fire for the specific requested event (sanic-org#2826).

Also added support for passing conditions= and exclusive= arguments to app.event().
talljosh added a commit to talljosh/sanic that referenced this issue Sep 25, 2023
…fire for the specific requested event (sanic-org#2826).

Also added support for passing conditions= and exclusive= arguments to app.event().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant