@@ -307,8 +307,8 @@ The :mod:`threading` module's locks and condition variables also support the
307
307
The lock is acquired before the block is executed and always released once the
308
308
block is complete.
309
309
310
- The :func: `decimal.localcontext ` function in the :mod: `decimal ` module makes
311
- it easy to save and restore the current decimal context, which encapsulates
310
+ The :func: `decimal.localcontext ` function in the :mod: `decimal ` module makes
311
+ it easy to save and restore the current decimal context, which encapsulates
312
312
the desired precision and rounding characteristics for computations::
313
313
314
314
from decimal import Decimal, Context, localcontext
@@ -337,11 +337,11 @@ underlying implementation and should keep reading.
337
337
A high-level explanation of the context management protocol is:
338
338
339
339
* The expression is evaluated and should result in an object called a "context
340
- manager". The context manager must have :meth: `~object.__enter__ ` and
340
+ manager". The context manager must have :meth: `~object.__enter__ ` and
341
341
:meth: `~object.__exit__ ` methods.
342
342
343
- * The context manager's :meth: `~object.__enter__ ` method is called. The value
344
- returned is assigned to *VAR *. If no ``as VAR `` clause is present, the
343
+ * The context manager's :meth: `~object.__enter__ ` method is called. The value
344
+ returned is assigned to *VAR *. If no ``as VAR `` clause is present, the
345
345
value is simply discarded.
346
346
347
347
* The code in *BLOCK * is executed.
@@ -431,14 +431,14 @@ The contextlib module
431
431
The :mod: `contextlib ` module provides some functions and a decorator that
432
432
are useful when writing objects for use with the ':keyword: `with `' statement.
433
433
434
- The decorator is called :func: `~contextlib.contextmanager `, and lets you write
435
- a single generator function instead of defining a new class. The generator
436
- should yield exactly one value. The code up to the :keyword: `yield ` will be
437
- executed as the :meth: `~object.__enter__ ` method, and the value yielded will
438
- be the method's return value that will get bound to the variable in the
439
- ':keyword: `with `' statement's :keyword: `!as ` clause, if any. The code after
440
- the :keyword: `!yield ` will be executed in the :meth: `~object.__exit__ ` method.
441
- Any exception raised in the block will be raised by the :keyword: `!yield `
434
+ The decorator is called :func: `~contextlib.contextmanager `, and lets you write
435
+ a single generator function instead of defining a new class. The generator
436
+ should yield exactly one value. The code up to the :keyword: `yield ` will be
437
+ executed as the :meth: `~object.__enter__ ` method, and the value yielded will
438
+ be the method's return value that will get bound to the variable in the
439
+ ':keyword: `with `' statement's :keyword: `!as ` clause, if any. The code after
440
+ the :keyword: `!yield ` will be executed in the :meth: `~object.__exit__ ` method.
441
+ Any exception raised in the block will be raised by the :keyword: `!yield `
442
442
statement.
443
443
444
444
Using this decorator, our database example from the previous section
@@ -572,8 +572,8 @@ approach of the module is still similar. The fundamental class
572
572
is the :class: `~multiprocessing.Process `, which is passed a callable object and
573
573
a collection of arguments. The :meth: `~multiprocessing.Process.start ` method
574
574
sets the callable running in a subprocess, after which you can call
575
- the :meth: `~multiprocessing.Process.is_alive ` method to check whether the
576
- subprocess is still running and the :meth: `~multiprocessing.Process.join `
575
+ the :meth: `~multiprocessing.Process.is_alive ` method to check whether the
576
+ subprocess is still running and the :meth: `~multiprocessing.Process.join `
577
577
method to wait for the process to exit.
578
578
579
579
Here's a simple example where the subprocess will calculate a
@@ -621,14 +621,14 @@ the object to communicate. (If the parent were to change the value of
621
621
the global variable, the child's value would be unaffected, and vice
622
622
versa.)
623
623
624
- Two other classes, :class: `~multiprocessing.pool.Pool ` and
625
- :class: `~multiprocessing.Manager `, provide higher-level interfaces.
626
- :class: `~multiprocessing.pool.Pool ` will create a fixed number of worker
627
- processes, and requests can then be distributed to the workers by calling
628
- :meth: `~multiprocessing.pool.Pool.apply ` or
629
- :meth: `~multiprocessing.pool.Pool.apply_async ` to add a single request, and
624
+ Two other classes, :class: `~multiprocessing.pool.Pool ` and
625
+ :class: `~multiprocessing.Manager `, provide higher-level interfaces.
626
+ :class: `~multiprocessing.pool.Pool ` will create a fixed number of worker
627
+ processes, and requests can then be distributed to the workers by calling
628
+ :meth: `~multiprocessing.pool.Pool.apply ` or
629
+ :meth: `~multiprocessing.pool.Pool.apply_async ` to add a single request, and
630
630
:meth: `map ` or :meth: `~multiprocessing.pool.Pool.map_async ` to add a number of
631
- requests. The following code uses a :class: `~multiprocessing.pool.Pool ` to
631
+ requests. The following code uses a :class: `~multiprocessing.pool.Pool ` to
632
632
spread requests across 5 worker processes and retrieve a list of results::
633
633
634
634
from multiprocessing import Pool
@@ -650,17 +650,17 @@ This produces the following output::
650
650
33452526613163807108170062053440751665152000000000
651
651
...
652
652
653
- The other high-level interface, the :class: `~multiprocessing.Manager ` class,
653
+ The other high-level interface, the :class: `~multiprocessing.Manager ` class,
654
654
creates a separate server process that can hold master copies of Python data
655
655
structures. Other processes can then access and modify these data
656
656
structures using proxy objects. The following example creates a
657
657
shared dictionary by calling the :meth: `dict ` method; the worker
658
658
processes then insert values into the dictionary. (Locking is not
659
659
done for you automatically, which doesn't matter in this example.
660
- :class: `~multiprocessing.Manager `'s methods also include
661
- :meth: `~multiprocessing.managers.SyncManager.Lock `,
660
+ :class: `~multiprocessing.Manager `'s methods also include
661
+ :meth: `~multiprocessing.managers.SyncManager.Lock `,
662
662
:meth: `~multiprocessing.managers.SyncManager.RLock `,
663
- and :meth: `~multiprocessing.managers.SyncManager.Semaphore ` to create
663
+ and :meth: `~multiprocessing.managers.SyncManager.Semaphore ` to create
664
664
shared locks.)
665
665
666
666
::
@@ -1036,21 +1036,21 @@ PEP 3116: New I/O Library
1036
1036
1037
1037
Python's built-in file objects support a number of methods, but
1038
1038
file-like objects don't necessarily support all of them. Objects that
1039
- imitate files usually support :meth: `~io.TextIOBase.read ` and
1040
- :meth: `~io.TextIOBase.write `, but they may not support :meth: `readline `,
1041
- for example. Python 3.0 introduces a layered I/O library in the :mod: `io `
1042
- module that separates buffering and text-handling features from the
1039
+ imitate files usually support :meth: `~io.TextIOBase.read ` and
1040
+ :meth: `~io.TextIOBase.write `, but they may not support :meth: `readline `,
1041
+ for example. Python 3.0 introduces a layered I/O library in the :mod: `io `
1042
+ module that separates buffering and text-handling features from the
1043
1043
fundamental read and write operations.
1044
1044
1045
1045
There are three levels of abstract base classes provided by
1046
1046
the :mod: `io ` module:
1047
1047
1048
1048
* :class: `~io.RawIOBase ` defines raw I/O operations: :meth: `~io.RawIOBase.read `,
1049
- :meth: `~io.RawIOBase.readinto `, :meth: `~io.RawIOBase.write `,
1049
+ :meth: `~io.RawIOBase.readinto `, :meth: `~io.RawIOBase.write `,
1050
1050
:meth: `~io.IOBase.seek `, :meth: `~io.IOBase.tell `, :meth: `~io.IOBase.truncate `,
1051
1051
and :meth: `~io.IOBase.close `.
1052
1052
Most of the methods of this class will often map to a single system call.
1053
- There are also :meth: `~io.IOBase.readable `, :meth: `~io.IOBase.writable `,
1053
+ There are also :meth: `~io.IOBase.readable `, :meth: `~io.IOBase.writable `,
1054
1054
and :meth: `~io.IOBase.seekable ` methods for determining what operations a
1055
1055
given object will allow.
1056
1056
@@ -1062,7 +1062,7 @@ the :mod:`io` module:
1062
1062
buffers data in memory to reduce the number of
1063
1063
system calls used, making I/O processing more efficient.
1064
1064
It supports all of the methods of :class: `~io.RawIOBase `,
1065
- and adds a :attr: `~io.BufferedIOBase.raw ` attribute holding the underlying
1065
+ and adds a :attr: `~io.BufferedIOBase.raw ` attribute holding the underlying
1066
1066
raw object.
1067
1067
1068
1068
There are five concrete classes implementing this ABC.
0 commit comments