我希望你做得很好。我对import uwsgi有问题,谢谢你的帮助,我的rabbitmq正在幕后工作,不用担心
我已经安装了2.0.15和2.0.18版本的uwsgi,我仍然尝试它不起作用,我的目的是导入uwsgi和
uwsgi.websocket_handshake(
env['HTTP_SEC_WEBSOCKET_KEY'],
env.get('HTTP_ORIGIN', '')
)如果我不能导入uwsgi,那么我就不能使用uwsgi.websocker_handshake
"""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‘的模块
发布于 2019-10-07 23:37:18
你如何开始你的代码?
如果您想导入uwsgi,您必须(如果我没记错的话)启动uwsgi可执行文件,它将依次启动uwsgi工作程序。然后,这些uwsgi工作人员可以导入uwsgi。
https://stackoverflow.com/questions/58271295
复制相似问题