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

updated race example to use variable assignment to track winner instead of memory channel #1978

Merged
merged 2 commits into from
Apr 26, 2021

Conversation

kbiggers
Copy link
Contributor

When I was first reading through the docs for trio I was a bit thrown off by the use of a memory channel in the race example. Since the memory channel itself is not what is meant to be demonstrated here, I think it might be better to remove it in favor of simple variable assignment. Another plus of this is it demonstrates the ability to use nurseries themselves for waiting.

I may be alone in being confused with the memory channel, so please let me know if you prefer it the original way, and also let me know if you have any questions about this.

Thanks!

@codecov
Copy link

codecov bot commented Apr 23, 2021

Codecov Report

Merging #1978 (bb04627) into master (813fc99) will decrease coverage by 0.04%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #1978      +/-   ##
==========================================
- Coverage   99.58%   99.54%   -0.05%     
==========================================
  Files         114      114              
  Lines       14627    14627              
  Branches     1119     1119              
==========================================
- Hits        14567    14561       -6     
- Misses         43       45       +2     
- Partials       17       21       +4     
Impacted Files Coverage Δ
trio/_core/tests/tutil.py 96.61% <0.00%> (-3.39%) ⬇️
trio/_core/_multierror.py 98.87% <0.00%> (-1.13%) ⬇️
trio/_core/tests/test_ki.py 99.13% <0.00%> (-0.87%) ⬇️
trio/_core/tests/test_multierror.py 99.27% <0.00%> (-0.73%) ⬇️
trio/tests/test_ssl.py 99.57% <0.00%> (-0.29%) ⬇️
trio/tests/test_testing.py 99.76% <0.00%> (-0.24%) ⬇️
trio/testing/_check_streams.py 99.33% <0.00%> (+0.66%) ⬆️
trio/tests/test_socket.py 100.00% <0.00%> (+0.81%) ⬆️

Copy link

@twosigmajab twosigmajab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @kbiggers! (Caught a minor issue in the code and left a suggested fix, but) the main change here makes sense to me: Folks new to Trio seem to reach for memory channels more often than more experienced users do, and it's interesting to learn that this particular section of the documentation was partly responsible for this for you and others, especially since it's currently the top result for e.g. https://trio.readthedocs.io/en/stable/search.html?q=race

Looks like these docs were last touched 3 years ago, so I wonder if we have a better understanding of Trionic style now, or if @njsmith thinks these docs should actually stay as-written. Looks like this was discussed in Gitter and @njsmith approved, nice. Sorry I missed that!

await send_channel.send(await async_fn())
async def jockey(async_fn, cancel_scope):
nonlocal winner
await winner = async_fn()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await winner = async_fn()
winner = await async_fn()

@kbiggers
Copy link
Contributor Author

ah good catch about the await, I'll fix that!

@njsmith
Copy link
Member

njsmith commented Apr 26, 2021

Failed test is spurious, caused by #1785 (comment)

Anyway, looks good, so thanks! Hopefully this will make the next reader's life just a little bit easier.

@njsmith njsmith merged commit 22f5e4d into python-trio:master Apr 26, 2021
@trio-bot
Copy link

trio-bot bot commented Apr 26, 2021

Hey @kbiggers, it looks like that was the first time we merged one of your PRs! Thanks so much! 🎉 🎂

If you want to keep contributing, we'd love to have you. So, I just sent you an invitation to join the python-trio organization on Github! If you accept, then here's what will happen:

  • Github will automatically subscribe you to notifications on all our repositories. (But you can unsubscribe again if you don't want the spam.)

  • You'll be able to help us manage issues (add labels, close them, etc.)

  • You'll be able to review and merge other people's pull requests

  • You'll get a [member] badge next to your name when participating in the Trio repos, and you'll have the option of adding your name to our member's page and putting our icon on your Github profile (details)

If you want to read more, here's the relevant section in our contributing guide.

Alternatively, you're free to decline or ignore the invitation. You'll still be able to contribute as much or as little as you like, and I won't hassle you about joining again. But if you ever change your mind, just let us know and we'll send another invitation. We'd love to have you, but more importantly we want you to do whatever's best for you.

If you have any questions, well... I am just a humble Python script, so I probably can't help. But please do post a comment here, or in our chat, or on our forum, whatever's easiest, and someone will help you out!

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.

3 participants