Comments (21)
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.
This is likely a problem in your application. Could you please share a simple client and server that reproduce this problem?
from python-socketio.
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.
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.
well i lost connection a bit before i died, and then disconnect didnt do anything
from python-socketio.
i do want reconnects tho, just not after sio.disconnect()
from python-socketio.
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.
@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.
@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.
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.
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.
it should cancel the reconnect.
from python-socketio.
As I said, I will think about how to interrupt a reconnect loop.
from python-socketio.
ok👍
from python-socketio.
from python-socketio.
from python-socketio.
@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.
ok
from python-socketio.
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.
@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.
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)
- May need to remove "pip install aioredis" from the documentation
- 5.10.0: pytest is failing HOT 4
- `max_http_buffer_size` value seem ignored by the server HOT 14
- Implementing `__enter__`/`__exit__` on `Client` like `SimpleClient` HOT 2
- Request: type hints (e.g. for mypy) HOT 3
- Update documentation of usage with Gunicorn + gevent/eventlet HOT 5
- Wildcard / catch-all namespace for event handlers HOT 1
- Heroku Problems with Gevent (Request Timeout + Polling Hanging)
- Concurrent broadcasting HOT 2
- All connections stop processing events at the same time
- Session not found when using sio.transport(sid) due to wrong session id HOT 1
- _ping background task not cancelled by async_server.shutdown() HOT 1
- Option to reconnect on initial connection failure
- Value error : Invalid aysnc_mode specified HOT 2
- Python socket ids for client and server dont match. HOT 6
- AsyncServer disconnect event not sent with `aiohttp>=3.9.0` HOT 2
- Test failure with .helpers import AsyncMock HOT 1
- Unable to cancel asynchronous task while client is reconnecting HOT 3
- Namespace catch-all logic HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-socketio.