首页 > 解决方案 > 我收到此错误:任务已销毁但未决

问题描述

from aioredis import (
    create_redis_pool
)

class RedisConn:
    def __init__(self):
        self.conn = None

    def set_conn(self, c):
        self.conn = c

    def get_conn(self):
        return self.conn


rdpsc = RedisConn()


async def init_redis_conn():
    connection = None
    try:
        connection = await create_redis_pool(
            'redis://localhost:6379',
            db=1
        )
        rdpsc.set_conn(connection)
    except Exception as excep:
        sentry_sdk.capture_exception(excep)

Task was destroyed but it is pending! 在使用时遇到此错误await init_redis_conn(),我在 Python 3.8 中使用 aioredis=1.3.1。请帮帮我谢谢

标签: pythonredisfastapiaioredis

解决方案


推荐阅读