shanealynn / async_flask

Test of asynchronous flask communication with web page.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How cancel randomgenerator after all connections is closed

sergeos opened this issue · comments

After remote user disconecting, random still generate numbers to port. How possible turn mashine to listening mode only? Not generate nedeed.
in terminal:

Client disconnected
4.123
3.216
4.084
7.176
8.667
8.728
7.459
...

To achieve this, I think you will need to manually keep a count of the number of clients connected in your Python application. On each new client, you will receive a "connect" event, and when they leave, a "disconnect" event - you can implement a counter based on this, and then stop the random generation based on the counter.

Does that make sense?

But which of command terminate generator?
i'm trying
'''
@socketio.on('disconnect', namespace='/test')
def test_disconnect():
print('Client disconnected')
thread._stop()
'''
but thread._stop() crash my app.
And how to write correctly?

I think you're on the right track - but you may need to add some sort of more complex object that is managing the thread activities so that you can pause it.

It's working fine, I've just updated to this versions:
jquery: 3.6.0
socket.io: 4.0.0
bootstrap: 4.6.0

Python 3
Flask==1.1.2
Flask-SocketIO==5.0.1
Jinja2==2.11.3
python-engineio==4.0.1
python-socketio==5.1.0

example running without error