Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add asyncio in multi-agent-applications.md to make examples can be run "as is". #630

Closed
wants to merge 3 commits into from

Conversation

ME-Msc
Copy link
Contributor

@ME-Msc ME-Msc commented Jan 7, 2025

Examples cannot be run "as is" without asyncio.

@samuelcolvin
Copy link
Member

you'll need to use single quotes.

Best to run tests before committing which will pick this up, if you run uv run pytest --update-examples, it'll even fix them for you.

@samuelcolvin
Copy link
Member

As I said before

Best to run tests before committing which will pick this up, if you run uv run pytest --update-examples, it'll even fix them for you.

@ME-Msc
Copy link
Contributor Author

ME-Msc commented Jan 7, 2025

As I said before

Best to run tests before committing which will pick this up, if you run uv run pytest --update-examples, it'll even fix them for you.

Thanks for your reply. I tried it and meet a failure. Could you help me with that? I have no idea.

bug

@samuelcolvin
Copy link
Member

😞 looks like a bug in pytest-examples we can't ignore, I'll try to fix it.

@ME-Msc
Copy link
Contributor Author

ME-Msc commented Jan 7, 2025

Ok, thank you. I will wait for it. I will create an issue about it.

@ME-Msc
Copy link
Contributor Author

ME-Msc commented Jan 7, 2025

#632 Have created an issue.

@samuelcolvin
Copy link
Member

Okay, I see what's going on here, the problem is caused by calling main twice: once with asyncio.run(main()) and once via the call argument here:

module_dict = eval_example.run_print_update(example, call=call_name)

Honestly I would rather keep the examples short and omit

if __name__ == '__main__':
    asyncio.run(main())

I think it's pretty obvious to most developers that you'll need to call main via asyncio.run(main()). Happy to accept a PR to add

_(This example is complete, it can be run "as is" — you'll need to add `asyncio.run(main())` to run `main`)_

to all examples that need it.

@ME-Msc
Copy link
Contributor Author

ME-Msc commented Jan 8, 2025

Thank you for your help!

A new PR #638 has been created.

And I suggest to add uv run pytest --update-examples in docs/contributing.md, helping newcomers like me to make contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants