Coder Social home page Coder Social logo

Comments (21)

blazing-gig avatar blazing-gig commented on June 14, 2024 1

I managed to achieve this by manually setting the _reconnect_abort event explicitly like so:

if self._sio_client.connected:
    await self._sio_client.disconnect()
    if self._sio_client._reconnect_abort:
        self._sio_client._reconnect_abort.set()

This seems to have worked.
@miguelgrinberg Could you pls comment on if this can serve as a potential workaround or even a fix ?

from python-socketio.

miguelgrinberg avatar miguelgrinberg commented on June 14, 2024

This is likely a problem in your application. Could you please share a simple client and server that reproduce this problem?

from python-socketio.

 avatar commented on June 14, 2024

I dont have a simple example of it, as its a pygame app

but here is some of the code with most stuff cut out that isnt socketio related

def multiplayer():
    global paddle_a, paddle_b, ball, ball_dx, ball_dy, score
    initialize_game()
    sio.connect('https://ultimatepingpongsocket.xytriza.com')
    while True:
        if ball.left <= 0:
            if sio.connected:
                sio.disconnect()
            initialize_game()
            death_screen(score, 2)
        if ball.right >= 800:
            if sio.connected:
                sio.disconnect()
            initialize_game()
            death_screen(score, 2)

        keys = pygame.key.get_pressed()
        if keys[pygame.K_w] and paddle_a.top > 0:
            paddle_a.y -= 5
            if sio.connected:
                sio.emit('send_position_2', paddle_a.y)
        if keys[pygame.K_s] and paddle_a.bottom < 600:
            paddle_a.y += 5
            if sio.connected:
                sio.emit('send_position_2', paddle_a.y)

        pygame.display.flip()
        pygame.time.Clock().tick(60)

for some reason if i send too many updates to the server itll cause a freeze

from python-socketio.

miguelgrinberg avatar miguelgrinberg commented on June 14, 2024

The logs do not show that you have initiated a disconnection, they show that the client lost the connection to the server, and for that reason it is attempting to reconnect. If you do not want reconnections to happen, you can disable it when you create the client object.

from python-socketio.

 avatar commented on June 14, 2024

well i lost connection a bit before i died, and then disconnect didnt do anything

from python-socketio.

 avatar commented on June 14, 2024

i do want reconnects tho, just not after sio.disconnect()

from python-socketio.

miguelgrinberg avatar miguelgrinberg commented on June 14, 2024

Let me see if I understand. You got disconnected from the server, and while the client was in the process of reconnecting you called disconnect()? And your expectation is that this will stop the reconnection?

from python-socketio.

vipcxj avatar vipcxj commented on June 14, 2024

@miguelgrinberg Hi, How can I recognize whether the disconnect event is triggered by invoking disconnect method or a network issue in on callback? I think we should use another event (maybe called close) to represent disconnect triggered bt user manually disconnect. The socket.io official provide a reason as the argument of the callback, however according document, python-socketio use a none argument callback for disconnect event. I think the official approach is bizarre, but at least it offers a solution

from python-socketio.

miguelgrinberg avatar miguelgrinberg commented on June 14, 2024

@vipcxj correct, the disconnect reason is not being exposed to the disconnect handler. I have never got around to expose that. Will think about how to best do this.

from python-socketio.

 avatar commented on June 14, 2024

Let me see if I understand. You got disconnected from the server, and while the client was in the process of reconnecting you called disconnect()? And your expectation is that this will stop the reconnection?

yes this is correct, when dropping connection to the server, and then disconnect() it should cancel the reconnect, not continue it as its meant to be disconnected

from python-socketio.

miguelgrinberg avatar miguelgrinberg commented on June 14, 2024

The thing is, calling disconnect when you are disconnected doesn't do anything, since you are already disconnected.

There is currently no way to interrupt a reconnect loop, but there are options to disable reconnects, or to indicate how many retries you want before giving up. I will consider adding a way to interrupt a reconnect loop in the future, but right now it is not possible.

from python-socketio.

 avatar commented on June 14, 2024

it should cancel the reconnect.

from python-socketio.

miguelgrinberg avatar miguelgrinberg commented on June 14, 2024

As I said, I will think about how to interrupt a reconnect loop.

from python-socketio.

 avatar commented on June 14, 2024

ok👍

from python-socketio.

 avatar commented on June 14, 2024

from python-socketio.

 avatar commented on June 14, 2024

from python-socketio.

blazing-gig avatar blazing-gig commented on June 14, 2024

@Xytriza You can get rid of the self if you aren't using classes. sio_client from my example above, is just an instance of socketio.AsyncClient.

from python-socketio.

 avatar commented on June 14, 2024

ok

from python-socketio.

miguelgrinberg avatar miguelgrinberg commented on June 14, 2024

I managed to achieve this by manually setting the _reconnect_abort event explicitly like so:

if self._sio_client.connected:
    await self._sio_client.disconnect()
    if self._sio_client._reconnect_abort:
        self._sio_client._reconnect_abort.set()

This seems to have worked. @miguelgrinberg Could you pls comment on if this can serve as a potential workaround or even a fix ?

This is not something that I would recommend, because you are using private attributes that are not guaranteed to be preserved in future releases, but as a temporary workaround it may be okay. You should probably wait for the reconnect task to end after signaling it to exit.

from python-socketio.

blazing-gig avatar blazing-gig commented on June 14, 2024

@miguelgrinberg Right. So I believe just adding this line should do:

if self._sio_client.connected:
    await self._sio_client.disconnect()
    if self._sio_client._reconnect_abort:
        self._sio_client._reconnect_abort.set()
        await self._sio_client._reconnect_task # Per your suggestion

from python-socketio.

miguelgrinberg avatar miguelgrinberg commented on June 14, 2024

Sure. As I said above though, I cannot guarantee that this will continue to work in future versions, since you are accessing privates/internals of the library.

from python-socketio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.