如何让dramatiq在windows/wsl环境中与redis一起工作?

6za6bjd0  于 2021-06-09  发布在  Redis
关注(0)|答案(0)|浏览(393)

我创建了一个简单的脚本,用redis来测试戏剧性:

broker_redis = RedisBroker(host='localhost', port=6379)

@dramatiq.actor
def sq(x):
    time.sleep(random.randint(2, 4))
    return x * x

我使用此命令在wsl内部运行(如文档所述):

dramatiq script_name:broker_redis

它运行时没有任何错误,并在控制台上打印出以下行:

[2020-05-06 09:46:28,535] [PID 508] [MainThread] [dramatiq.MainProcess] [INFO] Dramatiq '1.8.1' is booting up.
[2020-05-06 09:46:28,535] [PID 511] [MainThread] [dramatiq.WorkerProcess(1)] [INFO] Worker process is ready for action.
[2020-05-06 09:46:28,546] [PID 510] [MainThread] [dramatiq.WorkerProcess(0)] [INFO] Worker process is ready for action.
[2020-05-06 09:46:28,548] [PID 544] [MainThread] [dramatiq.ForkProcess(0)] [INFO] Fork process 'dramatiq.middleware.prometheus:_run_exposition_server' is ready for action.
[2020-05-06 09:46:28,559] [PID 513] [MainThread] [dramatiq.WorkerProcess(3)] [INFO] Worker process is ready for action.
[2020-05-06 09:46:28,569] [PID 512] [MainThread] [dramatiq.WorkerProcess(2)] [INFO] Worker process is ready for action.
[2020-05-06 09:46:28,581] [PID 515] [MainThread] [dramatiq.WorkerProcess(5)] [INFO] Worker process is ready for action.
[2020-05-06 09:46:28,596] [PID 514] [MainThread] [dramatiq.WorkerProcess(4)] [INFO] Worker process is ready for action.
[2020-05-06 09:46:28,634] [PID 516] [MainThread] [dramatiq.WorkerProcess(6)] [INFO] Worker process is ready for action.
[2020-05-06 09:46:28,634] [PID 517] [MainThread] [dramatiq.WorkerProcess(7)] [INFO] Worker process is ready for action.

但是当我在解释器中导入这个函数并使用 send 方法。。。

from script_name import sq
sq.send(10)

…它等待几秒钟,然后引发 dramatiq.errors.ConnectionClosed 错误:

dramatiq.errors.ConnectionClosed: AMQPConnectionError: (AMQPConnectorSocketConnectError: ConnectionRefusedError(10061, 'Unknown error'),)

似乎此调用无法将消息发送到wsl内部运行的戏剧化Q。
注意:我还没有安装rabbitmq,但是我假设如果我要使用redis,就不需要它。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题