6

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

2

2 Answers 2

3

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())
Sign up to request clarification or add additional context in comments.

Comments

1

The following code works with my poetry tool.script.

    def main():
        asyncio.run(start())
    
    
    if __name__ == "__main__":
        main()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.