title: gevent-socketio send message from thread
body: <p>I would like to use gevent-socketio to send messages from a worker thread and update all connected clients on the status of the job.</p>
  
  <p>I tried this:</p>
  
  <pre><code>from flask import Flask, render_template
  from flask.ext.socketio import SocketIO, send, emit
  import threading
  import time
  
  app = Flask(__name__)
  app.config['SECRET_KEY'] = 'secret!'
  socketio = SocketIO(app)
  
  @socketio.on('message')
  def handle_message(message):
      send(message, broadcast=True)
  
  @app.route('/')
  def index():
      return render_template('index.html')
  
  def ping_thread():
      while True:
          time.sleep(1)
          print 'Pinging'
          send('ping')
  
  if __name__ == '__main__':
      t = threading.Thread(target=ping_thread)
      t.daemon = True
      t.start()
      socketio.run(app)
  </code></pre>
  
  <p>And it gives me this error: </p>
  
  <pre><code>RuntimeError: working outside of request context
  </code></pre>
  
  <p>How do I send messages from a function that doesn't have the <code>@socketio.on()</code> decorator? Can I use <code>gevent</code> directly to send messages to <code>socketio</code>?</p>