-
-
Notifications
You must be signed in to change notification settings - Fork 335
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
clarified Nursery.start vs Nursery.start_soon #972
Conversation
Clarified the difference between start_soon and start. Mentioned that start_soon does not guarantee order.
Codecov Report
@@ Coverage Diff @@
## master #972 +/- ##
=======================================
Coverage 99.52% 99.52%
=======================================
Files 102 102
Lines 12192 12192
Branches 904 904
=======================================
Hits 12134 12134
Misses 36 36
Partials 22 22 |
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #972 +/- ##
=======================================
Coverage 99.52% 99.52%
=======================================
Files 102 102
Lines 12192 12192
Branches 904 904
=======================================
Hits 12134 12134
Misses 36 36
Partials 22 22 |
docs/source/history.rst
Outdated
@@ -5,6 +5,42 @@ Release history | |||
|
|||
.. towncrier release notes start | |||
|
|||
Trio 0.11.0+dev (2019-03-07) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The towncrier generated release notes shouldn't get checked in until we actually tag the release; the only change you would make is adding the new newsfragment file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted
docs/source/reference-core.rst
Outdated
actually get a chance to do anything until some later point when | ||
you execute a checkpoint and the scheduler decides to run it. | ||
If you want to run a function and immediately wait for its result, | ||
immediately, *before* it has a chance to run. At the next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a more stringent guarantee than we actually want to make -- #32 has some discussion of scheduling models that might want us to not switch tasks at every checkpoint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrote to not guarantee that tasks will launch at the next checkpoint.
@@ -0,0 +1 @@ | |||
Clarified documentation around Nursery.start_soon and Nursery.start, that start_soon does not guarantee task ordering, and when you should use each. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@njsmith - do we usually add newsfragments for documentation updates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs/source/reference-core.rst
Outdated
@@ -878,9 +881,9 @@ Nursery objects provide the following interface: | |||
The conventional way to define ``async_fn`` is like:: | |||
|
|||
async def async_fn(arg1, arg2, *, task_status=trio.TASK_STATUS_IGNORED): | |||
... | |||
... # some work before the parent may proceed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A task with task_status=trio.TASK_STATUS_IGNORED
can also be started with start_soon()
, in which case the parts before and after task_status.started()
behave the same as each other. Is there a different way to word this comment that might be clearer about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reworded to "some work the parent might wait for"
Thank you, @oremanj for your thorough and patient feedback. I'm not used to contributing to open source, and I appreciate your help greatly. Aside from the newsfragment note (which I'd be happy to go either way on) I think I addressed all your concerns. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution and for bearing with me on these changes! Here are a few more things I noticed on a second read -- sorry for being so nitpicky about this, but it's a pretty core aspect of the documentation and discusses a way in which Trio is unusual compared to other concurrency libraries, so I think it makes sense to polish extra-hard.
docs/source/reference-core.rst
Outdated
finished initializing itself, and optionally returns some | ||
information from it. | ||
Like :meth:`start_soon`, but blocks until the new child task | ||
signals that it may unblock, optionally returning additional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"signals" is a slightly overloaded word to use here due to Unix signals. Maybe "until the new child task indicates that it's finished starting up"? And I think the original "and optionally returns some information" is better than "optionally returning additional information" -- the more active phrasing tends to communicate more clearly IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing to "indicates"
later), all tasks requested with :meth:`start_soon` will begin, | ||
in no particular order. If you want to run a function to | ||
completion, then you don't need a nursery; just use | ||
``await async_fn(*args)``. If you want to run some part of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe "If you want to wait for the child task to finish starting up before the parent is allowed to proceed"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because "finish starting up" is not a meaningful concept until you've already bought into the abstraction of Nursery.start(). A task scheduled with start_soon might never call a task_status.started() function - but any programmer would say that task starts and ends and infers that it "finishes starting" somewhere in between. There needs to be some concept of the child signaling to the parent, even if we don't use the word "signal".
docs/source/reference-core.rst
Outdated
time, (which might be closing of the nursery context, but no | ||
later), all tasks requested with :meth:`start_soon` will begin, | ||
in no particular order. If you want to run a function to | ||
completion, then you don't need a nursery; just use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function always runs "to completion" (as opposed to being abandoned in the middle somewhere) regardless of whether you use await
or nursery.start_soon
. What are you trying to communicate here that you didn't feel was adequately communicated with "and immediately wait for its result"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The start function runs a function and immediately waits for a result too. It just so happens that the result might be returned by an intermediate result from a .started call in the middle.. I wanted to convey the difference. How about "If you want to run a function and block until it finishes" ?
docs/source/reference-core.rst
Outdated
continuing, see :meth:`start()`. | ||
immediately, *before* it has a chance to run. At some future | ||
time, (which might be closing of the nursery context, but no | ||
later), all tasks requested with :meth:`start_soon` will begin, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still could be read to imply that all of the tasks will be started at once, which isn't a guarantee we want to make. What if anything do you think is unclear about taking the previous wording ("won't actually get a chance to do anything ... the scheduler decides to run it") and adding a sentence like "Tasks might start running in a different order than the calls to start_soon()
"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right - it does imply a single time. Rephrased to "Tasks requested with :meth:start_soon
will begin, at no particular time, in no particular order (but no later than the closing of the nursery context)."
I wanted to avoid mention of the scheduler here. The important thing is that ordering and timing get arbitrary when you call start_soon - I don't think the reader will get that unless they have a good grasp of what the scheduler does and does not promise.
No problem! This documentation cost me personally hours of frustration and confusion. I'm more than happy to hammer it to death. |
What's left to fix for this PR? |
#970