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

clarified Nursery.start vs Nursery.start_soon #972

Closed
wants to merge 8 commits into from

Conversation

rotu
Copy link
Contributor

@rotu rotu commented Mar 7, 2019

rotu added 2 commits March 7, 2019 03:19
Clarified the difference between start_soon and start. Mentioned that start_soon does not guarantee order.
@codecov
Copy link

codecov bot commented Mar 7, 2019

Codecov Report

Merging #972 into master will not change coverage.
The diff coverage is n/a.

@@           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
Copy link

codecov bot commented Mar 7, 2019

Codecov Report

Merging #972 into master will not change coverage.
The diff coverage is n/a.

@@           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

@@ -5,6 +5,42 @@ Release history

.. towncrier release notes start

Trio 0.11.0+dev (2019-03-07)
Copy link
Member

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.

Copy link
Contributor Author

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 Show resolved Hide resolved
docs/source/reference-core.rst Outdated Show resolved Hide resolved
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
Copy link
Member

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.

Copy link
Contributor Author

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.
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@oremanj @njsmith Any opinions? I don't care whether we leave it in or take it out, but I'd like this pull request resolved

@@ -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
Copy link
Member

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?

Copy link
Contributor Author

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"

@rotu
Copy link
Contributor Author

rotu commented Mar 9, 2019

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.

Copy link
Member

@oremanj oremanj 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 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.

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
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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"

Copy link
Contributor Author

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".

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
Copy link
Member

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"?

Copy link
Contributor Author

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" ?

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,
Copy link
Member

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()"?

Copy link
Contributor Author

@rotu rotu Mar 9, 2019

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.

@rotu
Copy link
Contributor Author

rotu commented Mar 9, 2019

sorry for being so nitpicky about this, but it's a pretty core aspect of the documentation

No problem! This documentation cost me personally hours of frustration and confusion. I'm more than happy to hammer it to death.

@rotu
Copy link
Contributor Author

rotu commented May 10, 2019

What's left to fix for this PR?

@rotu rotu closed this Jul 4, 2019
@pquentin
Copy link
Member

pquentin commented Jul 5, 2019

@rotu I'm sorry that you had a bad experience here despite a very promising start. I personally don't feel qualified enough to look at this, but hopefully @oremanj will be able to look at this again at some point.

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