Async Partial Function Decorator
Archiviert 3 years ago
D
Dot
Verified
this is my decorator
and I want to call it without having to add the
so I added this
but it gives me the error
This is how I'm running the code btw
def pool_to_cursor(func:Callable[..., Any], pool:aiomysql.pool.Pool):
@functools.wraps(func)
async def wrapper(*args: Any, **kwargs: Any):
conn = await pool.acquire()
cursor = await conn.cursor()
result = await func(cursor,*args,**kwargs)
await conn.commit()
await cursor.close()
conn.close()
return result
return wrapper
and I want to call it without having to add the
(pool) everytime I do @pool_to_cursorso I added this
async def main() -> None:
global run_pool_to_cursor
pool = await generate_mariadb_connection()
run_pool_to_cursor = functools.partial(pool_to_cursor,pool=pool)but it gives me the error
NameError: name 'run_pool_to_cursor' is not defined.This is how I'm running the code btw
if __name__=="__main__":
asyncio.run(main())
