Skip to content

Commit a810d51

Browse files
committed
Update documentation for aiocontextvars 0.2
1 parent 64b28c7 commit a810d51

File tree

4 files changed

+20
-63
lines changed

4 files changed

+20
-63
lines changed

README.rst

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ Installation
5757

5858
.. code-block:: console
5959
60-
pip install gino aiocontextvars
61-
62-
(aiocontextvars_ is an optional dependency recommended for most users. It will
63-
be replaced_ by contextvars_, and it is not needed in upcoming `Python 3.7`_)
60+
pip install gino
6461
6562
6663
Showcase
@@ -248,7 +245,6 @@ hiring_!
248245
.. _`hire us`: https://decentfox.com/
249246
.. _`Become a patron`: https://www.patreon.com/fantixking
250247
.. _hiring: https://www.zhipin.com/gongsi/c6e283cf57f2d9361nF92NS7GA~~.html
251-
.. _aiocontextvars: https://github.com/fantix/aiocontextvars
252248
.. _contextvars: https://github.com/MagicStack/contextvars
253249
.. _replaced: https://github.com/MagicStack/contextvars/issues/2
254250
.. _`Python 3.7`: https://docs.python.org/3.7/library/contextvars.html

docs/engine.rst

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,12 @@ new head of the stack.
273273

274274
.. tip::
275275

276-
By context, we are actually referring to the context concept in either
277-
`aiocontextvars <https://github.com/fantix/aiocontextvars>`_ the optional
278-
dependency or `contextvars
279-
<https://docs.python.org/3.7/library/contextvars.html>`_ the new module in
280-
upcoming Python 3.7. Simply speaking, you may treat a function call chain
281-
including awaited :class:`~asyncio.Task` created in the chain as in the
282-
same context, something like a thread local in asyncio.
283-
284-
.. note::
285-
286-
And that is to say, `aiocontextvars
287-
<https://github.com/fantix/aiocontextvars>`_ is a required dependency for
288-
``reuse`` to work correctly in Python 3.6 - actually ``reuse`` is the
289-
reason for introducing context in the first place. Without context, the
290-
stack is always empty for any :meth:`~gino.engine.GinoEngine.acquire` thus
291-
no one could reuse any raw connection at all.
276+
By context, we are actually referring to the context concept in
277+
`contextvars <https://docs.python.org/3.7/library/contextvars.html>`_ the
278+
new module in Python 3.7, and its partial backport `aiocontextvars
279+
<https://github.com/fantix/aiocontextvars>`_. Simply speaking, you may
280+
treat a series of function calls in a chain as in the same context, even if
281+
there is an ``await``. It's something like a thread local in asyncio.
292282

293283
:class:`~gino.engine.GinoConnection` (2) may be created through
294284
``acquire(reuse=True)`` too - because the stack is empty before (2), there is
@@ -519,11 +509,3 @@ at the creation of :class:`~gino.api.Gino` instance. Therefore, any
519509
:class:`~sqlalchemy.sql.expression.Executable` object has the ``gino``
520510
property for implicit execution. Similarly, the execution methods calls the
521511
corresponding ones on the ``bind`` of the ``db`` instance.
522-
523-
.. warning::
524-
525-
The assumption for code above to run as expected is having
526-
`aiocontextvars <https://github.com/fantix/aiocontextvars>`_ installed on
527-
Python 3.6, or directly using Python 3.7. Or else, nested implicit
528-
executions will always run in a different new connection. This may be not
529-
so important here, but it is crucial for transactions.

docs/faq.rst

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,19 @@ available on :func:`~gino.create_engine` or :meth:`db.set_bind()
4141
engine = await gino.create_engine(..., ssl=True)
4242

4343

44-
Transaction cannot rollback changes?
45-
------------------------------------
44+
What is aiocontextvars and what does it do?
45+
-------------------------------------------
4646

47-
As for now, make sure `aiocontextvars
48-
<https://github.com/fantix/aiocontextvars>`_ is installed in order to use
49-
contextual transactions like this::
47+
It is a partial backport of the new built-in module `contextvars
48+
<https://docs.python.org/3.7/library/contextvars.html>`_ introduced in Python
49+
3.7. In Python 3.5 and 3.6, ``aiocontextvars`` patches ``loop.create_task()` to
50+
copy context from caller as a workaround to simulate the same behavior. This is
51+
also under discussion in upstream backport project, please read more here:
52+
https://github.com/MagicStack/contextvars/issues/2
5053
51-
async with db.transaction():
52-
await MyModel.create(name='xxx')
54+
If you are using Python 3.7, then ``aiocontextvars`` does nothing at all.
5355

54-
Or else if you'd prefer not to install an additional dependency, you'll have to
55-
modify the code to explicitly use the correct connection::
56+
.. note::
5657

57-
async with db.transaction() as tx:
58-
await MyModel.create(name='xxx', bind=tx.connection)
59-
60-
.. tip::
61-
62-
Since GINO 0.7.4, ``aiocontextvars`` became a required dependency.
58+
This answer is for GINO 0.8 and later, please check earlier versions of
59+
this documentation if you are using GINO 0.7.

docs/tutorial.rst

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,14 @@ code run faster, if not slower. Please read :doc:`why` for more information.
2727
Installation
2828
------------
2929

30-
.. note::
31-
32-
GINO optionally depends on aiocontextvars_ for sharing connection between
33-
method calls or chained coroutines without passing the connection object
34-
over and over again. It is highly recommended for most projects, unless you
35-
truly need a bare environment and handle connections manually.
36-
37-
.. important::
38-
39-
aiocontextvars_ will be replaced by `contextvars
40-
<https://github.com/MagicStack/contextvars>`__ once it `supports asyncio
41-
<https://github.com/MagicStack/contextvars/issues/2>`_. And neither will be
42-
needed in Python 3.7 which is delivered with a builtin `contextvars
43-
<https://docs.python.org/3.7/library/contextvars.html>`__ module.
44-
45-
.. _aiocontextvars: https://github.com/fantix/aiocontextvars
46-
47-
4830
Stable release
4931
^^^^^^^^^^^^^^
5032

5133
To install GINO, run this command in your terminal:
5234

5335
.. code-block:: console
5436
55-
$ pip install gino aiocontextvars
37+
$ pip install gino
5638
5739
This is the preferred method to install GINO, as it will always install the
5840
most recent stable release.

0 commit comments

Comments
 (0)