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

disconnect() within a receiver causes next receiver to not be called #8

Open
rothloup opened this issue Jan 11, 2025 · 0 comments
Open

Comments

@rothloup
Copy link

If multiple receivers are connected to the same signal from the same sender, and one of those receivers disconnects itself upon receiving the signal, this will the next receiver to not be called.

Example:

Expected output:

callback1
callback2
callback3

Actual Output:

callback1
callback3


from pydispatch import dispatcher


MYSIG = 'mysig'


def callback1():
    print('callback1')
    dispatcher.disconnect(callback1, MYSIG)


def callback2():
    print('callback2')
    dispatcher.disconnect(callback2, MYSIG)


def callback3():
    print('callback3')
    dispatcher.disconnect(callback3, MYSIG)


if __name__ == '__main__':
    dispatcher.connect(callback1, MYSIG)
    dispatcher.connect(callback2, MYSIG)
    dispatcher.connect(callback3, MYSIG)

    dispatcher.send(MYSIG)

I suspect that the problem in in dispatcher.send(), where the generator used in the for loop skips the (i)'th entry if the (i-1)'th was removed.


def send(signal=Any, sender=Anonymous, *arguments, **named):
    # Call each receiver with whatever arguments it can accept.
    # Return a list of tuple pairs [(receiver, response), ... ].
    responses = []
    for receiver in liveReceivers(getAllReceivers(sender, signal)):   # <---- This line skips an entry if a receiver is removed within the loop
        response = robustapply.robustApply(
            receiver,
            signal=signal,
            sender=sender,
            *arguments,
            **named
        )
        responses.append((receiver, response))
    return responses
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant