flask_socketio client does not receive a data that is processed in another request used multiprocess

Viewed 48

I am using flask with react in the client I am trying to make a loop to update data constantly but when I do the emit the data is not sent but the loop is done even if I put a string to send if it is reflected in the console.log

from flask import Flask, send_from_directory
from flask_socketio import SocketIO, emit, send
from flask_cors import CORS
from multiprocessing import Process, Queue
from servidor.api.api import Api_iv
import sys
ruta_template = '../../cliente/build'
app = Flask(__name__)#, static_folder=ruta_template+"/static/")
app.config['SECRET_KEY'] = '085i5RIlQM'
socket = SocketIO(app, cors_allowed_origins="*", async_mode='eventlet')
CORS(app)
#sys.setrecursionlimit(5000)

class Server_api:
    def __init__(self, socket):
        self.socket = socket

    def Get_api(self, q):
        api = Api_iv()
        data = api.Get_data()
        data_api = api.Parser_data(data)
        q.put(data_api)
        return

    def Multiprocess_api(self):
        data_process = Queue()
        process = Process(target=self.Get_api(data_process), args=(data_process,))
        process.start()
        process.join()
        return data_process.get()

@socket.on('stream')
def Stream_data():
    api = Server_api(socket)
    while True:
        print("Obteniendo Partidos...")
        emit("partidos", api.Multiprocess_api())
        socket.sleep(5)

if __name__ == '__main__':
    socket.run(app, debug=True)

client

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import io from 'socket.io-client';

const socket = io("http://127.0.0.1:5000");

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);
socket.emit("stream");
socket.on("partidos", (data) =>{
  console.log(data);
})




// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
reportWebVitals();

in the console.log nothing is reflected but on the server side if you do a loop and it is not seen that it is stuck only that it does not send the value

1 Answers

I already saw the problem, it was that I am sending data with many characters apparently sockeio cannot send data with many characters so I had to partition the sending into several parts so that it could be sent successfully ...

Related