Repository navigation
Conversation
Documentation build overview
8 files changed ·
|
Co-authored-by: Stan Ulbrych <stan@python.org>
StanFromIreland
left a comment
There was a problem hiding this comment.
INFO: task LGTM blocked for more than 120 seconds.
|
Looking... |
itamarst
left a comment
There was a problem hiding this comment.
There are two sets of comments:
- The ones for places where the terms were merely linked. Those could be skipped as out-of-scope (although it's always nice to improve things you're already touching).
- The ones on the actual definitions, which are more to the point of things I think that should probably be addressed.
|
|
||
| This coroutine function is primarily intended to be used for executing | ||
| IO-bound functions/methods that would otherwise block the event loop if | ||
| :term:`I/O-bound` functions/methods that would otherwise block |
There was a problem hiding this comment.
You can use it for CPU-bound tasks too?
There was a problem hiding this comment.
But I guess that's change of intention so maybe should be different PR.
There was a problem hiding this comment.
Oh but I see it's mentioned later, so it is OK with caveats.
| to make I/O-bound functions non-blocking. However, for extension modules | ||
| that release the GIL or alternative Python implementations that don't | ||
| have one, ``asyncio.to_thread()`` can also be used for CPU-bound functions. | ||
| have one, ``asyncio.to_thread()`` can also be used for |
| operations. This results in better performance for :term:`I/O-bound` use | ||
| cases. It also allows off-loading :term:`CPU-bound` work to a thread or | ||
| process pool, but that is still limited by the :term:`global | ||
| interpreter lock` in CPython. |
| sorting three of them takes about three seconds on one core and can take | ||
| as little as one second on three cores. With the | ||
| :term:`global interpreter lock`, only one thread runs Python bytecode at | ||
| a time, so threads do not speed up CPU-bound Python code. See also |
|
|
||
| CPU-bound | ||
| Describes a task that spends most of its time computing, which keeps a | ||
| CPU core busy. Running such tasks :term:`concurrently <concurrency>` on |
| by :pep:`492`. | ||
|
|
||
| CPU-bound | ||
| Describes a task that spends most of its time computing, which keeps a |
There was a problem hiding this comment.
"most of its time computing, for example doing mathematical calculations, or string manipulation, or or operating on an in-memory data structure. This keeps CPU core busy."
There was a problem hiding this comment.
I'd prefer we don't add too many examples, it overloads the definitions.
There was a problem hiding this comment.
Yeah, I think I'll just use a better example than string sorting. I'll give it a think. At one point this talked about compressing in-memory files but that makes the reader think about I/O which is exactly what this entry isn't about.
| CPU core busy. Running such tasks :term:`concurrently <concurrency>` on | ||
| one core does not finish the work sooner, because they take turns using | ||
| that core, but running them in :term:`parallel <parallelism>` on several | ||
| cores can. For example, if sorting a large list takes one second, |
There was a problem hiding this comment.
Sorting is maybe not the best example, parallel sorting being non-trivial. Summing a list of integers, maybe?
| another, so running such tasks :term:`concurrently <concurrency>` lets | ||
| their waits overlap, even on a single CPU core. For example, three | ||
| downloads that each take one second can finish in about one second when | ||
| run concurrently, instead of three. See also :term:`CPU-bound`. |
There was a problem hiding this comment.
"instead of three when run sequentially."
|
Thanks Itamar! I think I'll incorporate your suggestions for the glossary and leave the others alone. Lots of docs need updates along these lines and I wanted to keep this PR scoped to just the glossary. |
Adds glossary entries for "CPU-bound" and "I/O-bound" and links to them where the docs use the terms. The existing uses in the docs argues for explicitly and clearly defining these terms IMO.
The linked mentions now use the glossary spelling, replacing e.g. "IO bound" with "I/O-bound".
The second commit fixes a sentence in the asyncio docs that, in a parenthetical gloss, equates blocking code with CPU-bound code. Blocking I/O stalls the event loop too, so it deserves a mention as well.
The multi-threading HOWTO in #162624 will use both terms.