我正在尝试设置一个简单的flask
服务器:
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!'
但是我收到一个错误:
RuntimeError: cannot join current thread
我做错了什么?
在初始化期间指定我的 Pusher 集群帮助我摆脱了这个问题:
pusher = pysher.Pusher(
key=envkey.get('PUSHER_KEY'), # Or however you get the key
cluster="eu", # Add cluster!
)