Reputation: 33
Anytime I sent a post request to /tts/say or any other post request, the background task stops. Why is that and most importantly, how can I stop this behavior? I wasn't able to find more useful information, so if you miss some information, just ask, and I will try to provide it as quickly as possible. In the pepper.py there is connection to a python2 script via the socket module over port 9999. Here's the code from the main app.py:
import os
from flask import Flask
import flask
from flask_socketio import SocketIO
import pepper
import config
app = Flask(__name__)
socketio = SocketIO(app)
pepper = pepper.Pepper()
@app.route('/')
def main_get(): # put application's code here
return flask.render_template(
'index.html',
autonomous_life_options=pepper.get_autonomous_life_options(),
apps=pepper.get_installed_apps(),
postures=pepper.get_postures()
)
@app.route('/tts/say', methods=['POST'])
def tts_say():
text = flask.request.get_json()['text']
pepper.say(text)
return flask.Response("OK", status=200)
...
@socketio.on('connect')
def handle_connect():
print('Client connected: ', flask.request.remote_addr)
def send_updates():
while True:
socketio.sleep(1)
print("sending...")
socketio.emit('update_values', {
'volume': pepper.get_volume(),
'tablet_brightness': pepper.get_tablet_brightness(),
'autonomous_life_state': pepper.get_autonomous_life(),
'battery_level': pepper.get_battery_level(),
'apps_is_running': pepper.apps_is_running
})
if __name__ == '__main__':
socketio.start_background_task(send_updates)
socketio.run(app, **config.server_config_args)
print("Server listening on port 5005")
I now suspect the socket connection out of pepper.py (import socket) as if I modify my code to be more like this example (https://github.com/miguelgrinberg/Flask-SocketIO/blob/main/example/app.py) it still doesn't work, but if I run it without the pepper.py (in a test file) it works. I think I got near to what causes the problem, but I still don't understand why and who to fix it.
Upvotes: 0
Views: 33