[Python] How I can call asyncio code from sync function which called from other async function?

Discussão em 'Python' iniciado por Stack, Maio 16, 2025.

  1. Stack

    Stack Membro Participativo

    I need call async code from sync code which called from other async function

    I try to do Setting a descriptor in python3.5 asynchronously but this answer didn't help me


    async def first():
    return second()


    def second():
    # TODO: In this function I want to call function thrird,
    # and I want to call it asynchronous!
    # This function MUST be syncronious (for example __get__)


    async def third():
    await asyncio.sleep(1)


    async def main():
    await asyncio.gather(
    first(),
    first()
    )
    # must work 1 second


    asyncio.run(main())



    This code must work 1 sec, not 2

    Continue reading...

Compartilhe esta Página