| 1 |
.. _glossary_guide: |
| 2 |
|
| 3 |
Glossary |
| 4 |
======== |
| 5 |
|
| 6 |
This glossary provides a brief description of some of the terms used within |
| 7 |
Eventlet in general, and more specifically in the migration context. |
| 8 |
The goal of this glossary is to ensure that everybody has the same |
| 9 |
understanding of the used terms. |
| 10 |
|
| 11 |
For more information about anything the migration, see the |
| 12 |
:ref:`migration-guide`. |
| 13 |
|
| 14 |
.. _glossary-concurrency: |
| 15 |
|
| 16 |
Concurrency |
| 17 |
----------- |
| 18 |
|
| 19 |
**Concurrency** is when two or more tasks can start, run, and complete in |
| 20 |
overlapping time **periods**. It doesn't necessarily mean they'll ever both be |
| 21 |
running **at the same instant**. For example, *multitasking* on a single-core |
| 22 |
machine. |
| 23 |
|
| 24 |
.. _glossary-cooperative-multitasking: |
| 25 |
|
| 26 |
Cooperative Multitasking |
| 27 |
------------------------ |
| 28 |
|
| 29 |
Whenever a **thread** begins sleeping or awaiting network I/O, there is a |
| 30 |
chance for another thread to take the **GIL** and execute Python code. |
| 31 |
This is **cooperative multitasking**. |
| 32 |
|
| 33 |
.. _glossary-coro: |
| 34 |
|
| 35 |
Coro |
| 36 |
---- |
| 37 |
|
| 38 |
Using the name **coro** is a common convention in the Python API |
| 39 |
documentation. It refers to a coroutine; i.e., strictly speaking, the result |
| 40 |
of calling an async def function, and not the function itself. |
| 41 |
|
| 42 |
.. _glossary-coroutine: |
| 43 |
|
| 44 |
Coroutine |
| 45 |
--------- |
| 46 |
|
| 47 |
**Coroutines** are programs components that allow execution to be suspended |
| 48 |
and resumed, generalizing. They have been described as "functions whose |
| 49 |
execution you can pause". |
| 50 |
|
| 51 |
.. _glossary-future: |
| 52 |
|
| 53 |
Future |
| 54 |
------ |
| 55 |
|
| 56 |
A **future** represents a future completion state of some activity and is |
| 57 |
managed by the loop. A Future is a special low-level awaitable object that |
| 58 |
represents an eventual result of an asynchronous operation. |
| 59 |
|
| 60 |
.. _glossary-greenlet: |
| 61 |
|
| 62 |
Greenlet |
| 63 |
-------- |
| 64 |
|
| 65 |
A **greenlet** is a lightweight **coroutine** for in-process sequential |
| 66 |
concurrent programming (see **concurrency**). You can usually think of |
| 67 |
greenlets as cooperatively scheduled **threads**. The major differences are |
| 68 |
that since they’re cooperatively scheduled, you are in control of when they |
| 69 |
execute, and since they are **coroutines**, many greenlets can exist in a |
| 70 |
single native **thread**. |
| 71 |
|
| 72 |
Greenlets are cooperative (see **cooperative multitasking**) and sequential. |
| 73 |
This means that when one greenlet is running, no other greenlet can be |
| 74 |
running; the programmer is fully in control of when execution switches between |
| 75 |
greenlets. In other words ones, when using greenlets, should not expect |
| 76 |
**preemptive** behavior. |
| 77 |
|
| 78 |
Greenlet is also the name of a `library |
| 79 |
<https://greenlet.readthedocs.io/en/latest/>`_ that provide the greenlet |
| 80 |
mechanism. Eventlet is based on the greenlet library. |
| 81 |
|
| 82 |
.. _glossary-green-thread: |
| 83 |
|
| 84 |
Green Thread |
| 85 |
------------ |
| 86 |
|
| 87 |
A **green thread** is a **threads** that is scheduled by a runtime library |
| 88 |
or virtual machine (VM) instead of natively by the underlying operating system |
| 89 |
(OS). Green threads emulate multithreaded environments without relying on any |
| 90 |
native OS abilities, and they are managed in user space) instead of kernel |
| 91 |
space, enabling them to work in environments that do not have native thread |
| 92 |
support. |
| 93 |
|
| 94 |
.. _glossary-gil: |
| 95 |
|
| 96 |
Global Interpreter Lock (GIL) |
| 97 |
----------------------------- |
| 98 |
|
| 99 |
A **global interpreter lock (GIL**) is a lock used internally to CPython to |
| 100 |
ensure that only one **thread** runs in the Python VM at a time. In general, |
| 101 |
Python offers to switch among threads only between bytecode instructions (see |
| 102 |
**preemptive multitasking** and **cooperative multitasking**). |
| 103 |
|
| 104 |
.. _glossary-parallelism: |
| 105 |
|
| 106 |
Parallelism |
| 107 |
----------- |
| 108 |
|
| 109 |
**Parallelism** is when tasks *literally* run at the same time, e.g., on a |
| 110 |
multicore processor. A condition that arises when at least two threads are |
| 111 |
executing simultaneously. |
| 112 |
|
| 113 |
.. _glossary-preemptive: |
| 114 |
|
| 115 |
Preemptive/Preemption |
| 116 |
--------------------- |
| 117 |
|
| 118 |
**Preemption** is the act of temporarily interrupting an executing **task**, |
| 119 |
with the intention of resuming it at a later time. This interrupt is done by |
| 120 |
an external scheduler with no assistance or cooperation from the task. |
| 121 |
|
| 122 |
.. _glossary-preemptive-multitasking: |
| 123 |
|
| 124 |
Preemptive multitasking |
| 125 |
----------------------- |
| 126 |
|
| 127 |
**Preemptive multitasking** involves the use of an interrupt mechanism which |
| 128 |
suspends the currently executing process and invokes a scheduler to determine |
| 129 |
which process should execute next. Therefore, all processes will get some |
| 130 |
amount of CPU time at any given time. |
| 131 |
|
| 132 |
CPython also has **preemptive multitasking**: If a thread runs |
| 133 |
uninterrupted for 1000 bytecode instructions in Python 2, or runs 15 |
| 134 |
milliseconds in Python 3, then it gives up the GIL and another thread may run. |
| 135 |
|
| 136 |
.. _glossary-task: |
| 137 |
|
| 138 |
Task |
| 139 |
---- |
| 140 |
|
| 141 |
A **task** is a scheduled and independently managed **coroutine**. Tasks are |
| 142 |
awaitable objects used to schedule coroutines concurrently. |
| 143 |
|
| 144 |
.. _glossary-thread: |
| 145 |
|
| 146 |
Thread |
| 147 |
------ |
| 148 |
|
| 149 |
**Threads** are a way for a program to divide (termed "split") itself into two |
| 150 |
or more simultaneously (or pseudo-simultaneously) running tasks. Threads and |
| 151 |
processes differ from one operating system to another but, in general, a |
| 152 |
thread is contained inside a process and different threads in the same process |
| 153 |
share same resources while different processes in the same multitasking |
| 154 |
operating system do not. |
| 155 |
|
| 156 |
When do threads switch in Python? The switch depends on the context. The |
| 157 |
threads may be interrupted (see **preemptive multitasking**) or behave |
| 158 |
cooperatively (see **cooperative multitasking**). |