首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UWSGI没有名为uwsgi的模块

UWSGI没有名为uwsgi的模块
EN

Stack Overflow用户
提问于 2019-10-07 22:08:25
回答 1查看 406关注 0票数 0

我希望你做得很好。我对import uwsgi有问题,谢谢你的帮助,我的rabbitmq正在幕后工作,不用担心

我已经安装了2.0.15和2.0.18版本的uwsgi,我仍然尝试它不起作用,我的目的是导入uwsgi和

代码语言:javascript
复制
uwsgi.websocket_handshake(
        env['HTTP_SEC_WEBSOCKET_KEY'],
        env.get('HTTP_ORIGIN', '')
    )

如果我不能导入uwsgi,那么我就不能使用uwsgi.websocker_handshake

代码语言:javascript
复制
"""Receive messages over from RabbitMQ and send them over the websocket."""

import sys

import pika
import uwsgi


def application(env, start_response):
    """Setup the Websocket Server and read messages off the queue."""
    connection = pika.BlockingConnection(
    pika.ConnectionParameters(host='localhost')
    )
    channel = connection.channel()

    exchange = env['PATH_INFO'].replace('/', '')

    channel.exchange_declare(
        exchange=exchange, exchange_type='fanout'
    )

    # exclusive means the queue should be deleted once the connection is closed
    result = channel.queue_declare(exclusive=True)
    queue_name = result.method.queue  # random queue name generated by RabbitMQ

    channel.queue_bind(exchange=exchange, queue=queue_name)

    uwsgi.websocket_handshake(
        env['HTTP_SEC_WEBSOCKET_KEY'],
        env.get('HTTP_ORIGIN', '')
    )

    def keepalive():
        """Keep the websocket connection alive (called every 30 seconds)."""
        print('PING/PONG...')
        try:
            uwsgi.websocket_recv_nb()
            connection.add_timeout(30, keepalive)
        except OSError as error:
            connection.close()
            print(error)
            sys.exit(1)  # Kill process and force uWSGI to Respawn

    keepalive()

    while True:
        for method_frame, _, body in channel.consume(queue_name):
            try:
                uwsgi.websocket_send(body)
            except OSError as error:
                print(error)
                sys.exit(1)  # Force uWSGI to Respawn
            else:
                # acknowledge the message
                channel.basic_ack(method_frame.delivery_tag)

回溯(最近一次调用):导入uwsgi ModuleNotFoundError中的文件"websocket.py",第6行:没有名为'uwsgi‘的模块

EN

回答 1

Stack Overflow用户

发布于 2019-10-07 23:37:18

你如何开始你的代码?

如果您想导入uwsgi,您必须(如果我没记错的话)启动uwsgi可执行文件,它将依次启动uwsgi工作程序。然后,这些uwsgi工作人员可以导入uwsgi。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58271295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档