如何使用Flask设置推送服务器?

2024-09-29 05:18:25 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我做错了什么


Tags: fromimportappflaskmydefconnectsubscribe