4

I want to run python asynchronous script with poetry tool script. Could you please help? In pyproject.toml, I added like this.

[tool.poetry.scripts]
clear_data = "clear_data.clear_data:main"

In my python file, I wrote like this.

from anyio import run

async def main():
    pass

if __name__ == "__main__":
    run(main)

`

I have with poetry tool script. But faced this error.

RuntimeWarning: coroutine 'main' was never awaited
  main()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

oguz ismail
  • 1
  • 16
  • 47
  • 69
Julia
  • 51
  • 4

2 Answers2

1

I guess the simplest way is to use sync entrypoint, which invokes async top-level function as per Simplest async/await example possible in Python

import asyncio

async def run():
    pass

def main():
    asyncio.run(run())
nazgul
  • 449
  • 1
  • 4
  • 10
0

The following code works with my poetry tool.script.

    def main():
        asyncio.run(start())
    
    
    if __name__ == "__main__":
        main()
Julia
  • 51
  • 4