gpt4 book ai didi

python - 如何使用Flask设置Pusher服务器?

转载 作者:行者123 更新时间:2023-12-03 16:23:22 33 4
gpt4 key购买 nike

我正在尝试设置一个简单的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!
)

关于python - 如何使用Flask设置Pusher服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62559540/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com