@@ -38,7 +38,7 @@ Example
3838-------
3939
4040``playhouse.pwasyncio `` contains the async database implementations. Typically
41- this is the only thing you will need in order to use Peewee with asyncio:
41+ this is the only thing you need to use Peewee with asyncio:
4242
4343.. code-block :: python
4444
@@ -110,14 +110,13 @@ performs I/O. Whenever a query executes, control switches to the event loop and
110110the I/O coroutine is awaited like any other awaitable. Then the original call
111111resumes with the result.
112112
113- This is real asyncio, NOT gevent-style concurrency. Nothing is
113+ This is real asyncio, not gevent-style concurrency. Nothing is
114114monkey-patched, no sockets are wrapped, and the event loop is the ordinary
115115asyncio loop running the rest of your application.
116116
117- To show how this works I'll walk through the following example, which uses two
118- internal primitives ``greenlet_spawn `` (run sync code in a greenlet) and ``await_ ``
119- (suspend the sync greenlet, passing control and a coroutine to the async
120- parent).
117+ The following example uses two internal primitives, ``greenlet_spawn `` (run sync
118+ code in a greenlet) and ``await_ `` (suspend the sync greenlet, passing control
119+ and a coroutine to the async parent).
121120
122121.. code-block :: python
123122
@@ -147,7 +146,7 @@ When this runs:
147146 the bridge between sync and async python. Inside the new greenlet everything
148147 is synchronous, but it can yield coroutines to the async-world parent, which
149148 then awaits them on the loop.
150- 3. Inside the new greenlet we begin executing ``synchronous() `` (it does NOT know
149+ 3. Inside the new greenlet we begin executing ``synchronous() `` (it does not know
151150 anything about asyncio). ``a_add(1, 2) `` creates a coroutine, which gets passed
152151 to ``await_() ``.
1531524. Inside ``await_() ``, we *switch contexts * back to the parent (async world),
@@ -176,10 +175,9 @@ asynchronously:
176175
177176 In your code you should never need to use ``greenlet_spawn() `` or ``await_() ``
178177directly. Peewee wraps all this in ``a ``-prefixed methods and helpers so that the
179- greenlet machinery remains an implementation detail, but it's worth taking a
180- look at to understand what's going on. In short, Peewee uses greenlets to pass
181- coroutines out of synchronous code, so they can be ``await ``-ed, at the cost of
182- two lightweight context switches.
178+ greenlet machinery remains an implementation detail. Peewee uses greenlets to
179+ pass coroutines out of synchronous code, so they can be ``await ``-ed, at the cost
180+ of two lightweight context switches.
183181
184182Async Model Methods
185183-------------------
@@ -341,7 +339,7 @@ For single-query operations, the async helpers are more direct:
341339 cursor = await query.aexecute()
342340
343341 # Use a transaction:
344- async with db.atomic() as tx :
342+ async with db.atomic():
345343 await db.run(User.create, name = ' Bob' )
346344
347345 # SELECT and return one model instance (raises DoesNotExist if none).
@@ -435,10 +433,8 @@ Explicit control is also available:
435433 # ... queries ...
436434 await db.aclose() # Release connection back to pool.
437435
438- Each asyncio task gets its own connection from the pool. **Connections are not
439- shared between tasks **. Each async task will have its own connection and
440- transaction state - this prevents bugs that may occur when connections are
441- shared and transactions end up interleaved across several running tasks.
436+ Each asyncio task gets its own connection and transaction state, so tasks never
437+ interleave each other's transactions.
442438
443439To shut down completely (e.g. during application teardown):
444440
@@ -491,9 +487,8 @@ writes will not occur "faster", the bottleneck has merely been moved.
491487Conversely, if you don't have that much load, the async wrapper adds complexity
492488and overhead for no measurable benefit.
493489
494- To use SQLite in an async environment anyways, it is strongly recommended to
495- use WAL-mode at a minimum, which allows multiple readers to co-exist with a
496- single writer:
490+ To use SQLite in an async environment anyway, use WAL-mode at a minimum, which
491+ allows multiple readers to co-exist with a single writer:
497492
498493.. code-block :: python
499494
0 commit comments