2

I am trying to integrate Flask-SocketIO into my application and having bad time. I don't understand how to pass SocketIO instance within the same context. Sorry i can't provide you with the exact code or error logs atm.

Any help would be greatly appreciated. If you have any questions regarding this ticket, feel free to ask.

run.py (<-- Application starts from here)

from app import app, socketio
socketio.run(app)

app/__init__.py

import json, stomp
from flask import Flask, render_template, jsonify, request
from app.dalet.DAPIDB import Handler
from flask.ext.bower import Bower
from flask_socketio import SocketIO

app = Flask(__name__)
socketio = SocketIO(app)
Bower(app)
with open('env.json') as data_file:
    app.config['locale'] = json.load(data_file)['locale']
app.config.from_object("config."+app.config['locale'])
API = Handler(app.config)

from app.dalet.LotusOrb import LotusOrb
conn = stomp.Connection()
conn.set_listener('', LotusOrb(API))
conn.start()
conn.connect('admin', 'admin', wait=True)
conn.subscribe('Mortred', 0)

app/dalet/LotusOrb.py

import stomp
from bs4 import BeautifulSoup
from app import socketio

class LotusOrb(stomp.ConnectionListener):
    def __init__(self, API):
        self.API = API
    def on_error(self, headers, rawmessage):
        print('received an error "%s"' % rawmessage)
    def on_message(self, headers, rawmessage):
        socketio.emit('current_title', self.API.getduration(itemidmb))

Obviously enough, i just need to execute socketio.emit. Application boots up, but client-side JS doesn't show up any message. (I'm 100% sure in client JS, it works if i write code in app/init.py) There is no error in output whatsoever, the mistake is probably in instances of socketio variable.

What's wrong with my importing?

EDIT: I've updated code.

1
  • 2
    Whenever you report an error, please add the complete stack trace to help people understand what's going on. Commented Nov 10, 2015 at 1:55

1 Answer 1

1

If you haven't already, you'll need to monkey patch the std libs according to whichever framework you're using to run your server:

# probably
from gevent import monkey; monkey.patch_all()
# or possibly
import eventlet; eventlet.monkey_patch()

I had a similar issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.