infothrill / flask-socketio-dbus-demo

A Flask demo app connecting the UPower battery status with DBUS to a website with socket.io
MIT License
8 stars 4 forks source link

socketio_emit() in background thread in called but never emit to client side #46

Open greggzj opened 5 years ago

greggzj commented 5 years ago

Hello, thanks for sharing the great demo repository. Just find a little problem regarding to socketio_emit() in function socketio_notify in background thread. Hoping for your feedback, thanks in advance!

This demo using built in Thread to start a background (rather than using eventlet to spawn a thread), and start the socketio in main thread. Which means that when specific dbus signal is recevied, the socketio_emit() in another thread (background) will be triggered.

But actually when receving the dbus signal, socketio_emit() is triggered but client side won't received any message emit by server.

Since requirements.txt contains eventlet which is the first choice as per flask socketio document. If I added

import eventlet
eventlet.monkey_patch()

at the front of run.py , or

explicily setting async_mode to threading as input parameter when initiating socketIO

this problem will be resolved.

Not digging further on eventlet/gevent/threading....If you know , please do not hesitate to tell me.

Hoping for your feedback!

greggzj commented 5 years ago

The environment was on Ubuntu 18.04.