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

标签 python flask websocket pusher

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

相关文章:

javascript - 带有 Websockets/socket.io 的 Ember.js。用于加载实时数据的 Ember API 调用/推荐结构

python - 为什么我会从 AWS API Gateway 收到 Forbidden 消息,即使一切都在内部运行?

python - 在 Python 3 中增加字节数组?

python - 使用 Flask 将表单数据保存在 url 中

python - Python 中使用 asyncio 的多个 websocket 流

python-2.7 - celery :错误:无法识别的参数:-A,Flask,argparse

python - Flask babel 无法进行简单翻译?

python - 在 Spyder 错误中导入模块

python - Pandas :过滤组中的唯一值

Python - 迭代整数列表