OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

sharing a python object in realtime between socketIO and flask app

  • Thread starter Thread starter Noemi Garau
  • Start date Start date
N

Noemi Garau

Guest
I'm working with a web app that is based on socketIO and flask. The problem is that i have a shared object that is changed when a post request is done. However, these changes are not always visible when socketio.emit is called.

Specifically I have a similar situation:

script socket_script.py

Code:
from helper import classA
from flaskapp_script import flask_routes

app.register_blueprint(flask_routes)
    
while True:
    if classA.state == 'decoding':
           
        roi_object = classA.listA

     else:
         roi_object = None
     socketio.emit('data_updated', roi_object)


script flaskapp_script.py
from helper import classA

flask_routes = Blueprint('http_test', __name__)

@flask_routes.route("/detect", methods=["GET","POST"])
def detect():
    
    classA.state = 'decoding'
    for i in range(len(classA.rois)):
       classA.rois['processed'] = True

Considering the reported example, the problem is that classA.rois (which is a list), sometimes results not updated in socket_script.py.

Any explanation related to this behaviour? How do you suggest to solve this problem?

I already compared carefully what happens to classA.rois list in the two files...
<p>I'm working with a web app that is based on socketIO and flask. The problem is that i have a shared object that is changed when a post request is done. However, these changes are not always visible when socketio.emit is called.</p>
<p>Specifically I have a similar situation:</p>
<p>script socket_script.py</p>
<pre><code>from helper import classA
from flaskapp_script import flask_routes

app.register_blueprint(flask_routes)

while True:
if classA.state == 'decoding':

roi_object = classA.listA

else:
roi_object = None
socketio.emit('data_updated', roi_object)


script flaskapp_script.py
from helper import classA

flask_routes = Blueprint('http_test', __name__)

@flask_routes.route("/detect", methods=["GET","POST"])
def detect():

classA.state = 'decoding'
for i in range(len(classA.rois)):
classA.rois['processed'] = True

</code></pre>
<p>Considering the reported example, the problem is that classA.rois (which is a list), sometimes results not updated in socket_script.py.</p>
<p>Any explanation related to this behaviour? How do you suggest to solve this problem?</p>
<p>I already compared carefully what happens to classA.rois list in the two files...</p>
 

Latest posts

B
Replies
0
Views
1
Blundering Ecologist
B
Top