I am trying to setup a simple flask
server:
import envkey
import pysher
from flask import Flask
# from predictor import PythonPredictor
app = Flask(__name__)
pusher = pysher.Pusher(envkey.get('PUSHER_KEY'))
def my_func(*args, **kwargs):
print("processing Args:", args)
print("processing Kwargs:", kwargs)
# We can't subscribe until we've connected, so we use a callback handler
# to subscribe when able
def connect_handler(data):
print('connect habndler')
channel = pusher.subscribe('mychannel')
channel.bind('myevent', my_func)
pusher.connection.bind('pusher:connection_established', connect_handler)
@app.route('/')
def index():
pusher.connect()
return 'Server Works!'
But I Get an error:
RuntimeError: cannot join current thread
What am I doing wrong?
Specifying my Pusher cluster during initalization helped me get rid of that issue:
pusher = pysher.Pusher(
key=envkey.get('PUSHER_KEY'), # Or however you get the key
cluster="eu", # Add cluster!
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With