@@ -386,7 +386,7 @@ The :mod:`multiprocessing` package mostly replicates the API of the
386
386
Unix daemons or services, they are normal processes that will be
387
387
terminated (and not joined) if non-daemonic processes have exited.
388
388
389
- In addition to the :class: `Threading .Thread ` API, :class: `Process ` objects
389
+ In addition to the :class: `threading .Thread ` API, :class: `Process ` objects
390
390
also support the following attributes and methods:
391
391
392
392
.. attribute :: pid
@@ -405,7 +405,7 @@ The :mod:`multiprocessing` package mostly replicates the API of the
405
405
The process's authentication key (a byte string).
406
406
407
407
When :mod: `multiprocessing ` is initialized the main process is assigned a
408
- random string using :func: `os.random `.
408
+ random string using :func: `os.urandom `.
409
409
410
410
When a :class: `Process ` object is created, it will inherit the
411
411
authentication key of its parent process, although this may be changed by
@@ -530,7 +530,7 @@ Note that one can also create a shared queue by using a manager object -- see
530
530
(1) After putting an object on an empty queue there may be an
531
531
infinitesimal delay before the queue's :meth: `~Queue.empty `
532
532
method returns :const: `False ` and :meth: `~Queue.get_nowait ` can
533
- return without raising :exc: `Queue .Empty `.
533
+ return without raising :exc: `queue .Empty `.
534
534
535
535
(2) If multiple processes are enqueuing objects, it is possible for
536
536
the objects to be received at the other end out-of-order.
@@ -547,7 +547,8 @@ Note that one can also create a shared queue by using a manager object -- see
547
547
.. warning ::
548
548
549
549
As mentioned above, if a child process has put items on a queue (and it has
550
- not used :meth: `JoinableQueue.cancel_join_thread `), then that process will
550
+ not used :meth: `JoinableQueue.cancel_join_thread
551
+ <multiprocessing.Queue.cancel_join_thread> `), then that process will
551
552
not terminate until all buffered items have been flushed to the pipe.
552
553
553
554
This means that if you try joining that process you may get a deadlock unless
@@ -580,7 +581,7 @@ For an example of the usage of queues for interprocess communication see
580
581
thread is started which transfers objects from a buffer into the pipe.
581
582
582
583
The usual :exc: `queue.Empty ` and :exc: `queue.Full ` exceptions from the
583
- standard library's :mod: `Queue ` module are raised to signal timeouts.
584
+ standard library's :mod: `queue ` module are raised to signal timeouts.
584
585
585
586
:class: `Queue ` implements all the methods of :class: `queue.Queue ` except for
586
587
:meth: `~queue.Queue.task_done ` and :meth: `~queue.Queue.join `.
@@ -696,7 +697,7 @@ For an example of the usage of queues for interprocess communication see
696
697
call to :meth: `task_done ` tells the queue that the processing on the task
697
698
is complete.
698
699
699
- If a :meth: `~Queue.join ` is currently blocking, it will resume when all
700
+ If a :meth: `~queue. Queue.join ` is currently blocking, it will resume when all
700
701
items have been processed (meaning that a :meth: `task_done ` call was
701
702
received for every item that had been :meth: `~Queue.put ` into the queue).
702
703
@@ -712,7 +713,7 @@ For an example of the usage of queues for interprocess communication see
712
713
queue. The count goes down whenever a consumer calls
713
714
:meth: `task_done ` to indicate that the item was retrieved and all work on
714
715
it is complete. When the count of unfinished tasks drops to zero,
715
- :meth: `~Queue.join ` unblocks.
716
+ :meth: `~queue. Queue.join ` unblocks.
716
717
717
718
718
719
Miscellaneous
@@ -874,8 +875,8 @@ Connection objects are usually created using :func:`Pipe` -- see also
874
875
875
876
.. versionadded :: 3.3
876
877
Connection objects now support the context manager protocol -- see
877
- :ref: `typecontextmanager `. :meth: `__enter__ ` returns the
878
- connection object, and :meth: `__exit__ ` calls :meth: `close `.
878
+ :ref: `typecontextmanager `. :meth: `~contextmanager. __enter__ ` returns the
879
+ connection object, and :meth: `~contextmanager. __exit__ ` calls :meth: `close `.
879
880
880
881
For example:
881
882
@@ -948,7 +949,7 @@ object -- see :ref:`multiprocessing-managers`.
948
949
object from :mod: `multiprocessing `.
949
950
950
951
.. versionchanged :: 3.3
951
- The :meth: `wait_for ` method was added.
952
+ The :meth: `~threading.Condition. wait_for ` method was added.
952
953
953
954
.. class :: Event()
954
955
@@ -1095,8 +1096,9 @@ processes.
1095
1096
array.
1096
1097
1097
1098
If *lock * is ``True `` (the default) then a new lock object is created to
1098
- synchronize access to the value. If *lock * is a :class: `Lock ` or
1099
- :class: `RLock ` object then that will be used to synchronize access to the
1099
+ synchronize access to the value. If *lock * is a
1100
+ :class: `~multiprocessing.Lock ` or :class: `~multiprocessing.RLock ` object
1101
+ then that will be used to synchronize access to the
1100
1102
value. If *lock * is ``False `` then access to the returned object will not be
1101
1103
automatically protected by a lock, so it will not necessarily be
1102
1104
"process-safe".
@@ -1110,8 +1112,8 @@ processes.
1110
1112
object.
1111
1113
1112
1114
If *lock * is ``True `` (the default) then a new lock object is created to
1113
- synchronize access to the value. If *lock * is a :class: `Lock ` or
1114
- :class: `RLock ` object then that will be used to synchronize access to the
1115
+ synchronize access to the value. If *lock * is a :class: `~multiprocessing. Lock ` or
1116
+ :class: `~multiprocessing. RLock ` object then that will be used to synchronize access to the
1115
1117
value. If *lock * is ``False `` then access to the returned object will not be
1116
1118
automatically protected by a lock, so it will not necessarily be
1117
1119
"process-safe".
@@ -1296,8 +1298,8 @@ their parent process exits. The manager classes are defined in the
1296
1298
:attr: `proxytype._exposed_ ` is used instead if it exists.) In the case
1297
1299
where no exposed list is specified, all "public methods" of the shared
1298
1300
object will be accessible. (Here a "public method" means any attribute
1299
- which has a :meth: `__call__ ` method and whose name does not begin with
1300
- ``'_' ``.)
1301
+ which has a :meth: `~object. __call__ ` method and whose name does not begin
1302
+ with ``'_' ``.)
1301
1303
1302
1304
*method_to_typeid * is a mapping used to specify the return type of those
1303
1305
exposed methods which should return a proxy. It maps method names to
@@ -1318,11 +1320,11 @@ their parent process exits. The manager classes are defined in the
1318
1320
1319
1321
.. versionchanged :: 3.3
1320
1322
Manager objects support the context manager protocol -- see
1321
- :ref: `typecontextmanager `. :meth: `__enter__ ` starts the server
1322
- process (if it has not already started) and then returns the
1323
- manager object. :meth: `__exit__ ` calls :meth: `shutdown `.
1323
+ :ref: `typecontextmanager `. :meth: `~contextmanager. __enter__ ` starts the
1324
+ server process (if it has not already started) and then returns the
1325
+ manager object. :meth: `~contextmanager. __exit__ ` calls :meth: `shutdown `.
1324
1326
1325
- In previous versions :meth: `__enter__ ` did not start the
1327
+ In previous versions :meth: `~contextmanager. __enter__ ` did not start the
1326
1328
manager's server process if it was not already started.
1327
1329
1328
1330
.. class :: SyncManager
@@ -1354,7 +1356,7 @@ their parent process exits. The manager classes are defined in the
1354
1356
:class: `threading.Lock ` or :class: `threading.RLock ` object.
1355
1357
1356
1358
.. versionchanged :: 3.3
1357
- The :meth: `wait_for ` method was added.
1359
+ The :meth: `~threading.Condition. wait_for ` method was added.
1358
1360
1359
1361
.. method :: Event()
1360
1362
@@ -1798,8 +1800,8 @@ with the :class:`Pool` class.
1798
1800
1799
1801
.. versionadded :: 3.3
1800
1802
Pool objects now support the context manager protocol -- see
1801
- :ref: `typecontextmanager `. :meth: `__enter__ ` returns the pool
1802
- object, and :meth: `__exit__ ` calls :meth: `terminate `.
1803
+ :ref: `typecontextmanager `. :meth: `~contextmanager. __enter__ ` returns the
1804
+ pool object, and :meth: ~contextmanager. `__exit__` calls :meth: `terminate `.
1803
1805
1804
1806
1805
1807
.. class :: AsyncResult
@@ -1860,7 +1862,8 @@ Listeners and Clients
1860
1862
:synopsis: API for dealing with sockets.
1861
1863
1862
1864
Usually message passing between processes is done using queues or by using
1863
- :class: `Connection ` objects returned by :func: `Pipe `.
1865
+ :class: `~multiprocessing.Connection ` objects returned by
1866
+ :func: `~multiprocessing.Pipe `.
1864
1867
1865
1868
However, the :mod: `multiprocessing.connection ` module allows some extra
1866
1869
flexibility. It basically gives a high level message oriented API for dealing
@@ -1928,7 +1931,8 @@ multiple connections at the same time.
1928
1931
private temporary directory created using :func: `tempfile.mkstemp `.
1929
1932
1930
1933
If the listener object uses a socket then *backlog * (1 by default) is passed
1931
- to the :meth: `listen ` method of the socket once it has been bound.
1934
+ to the :meth: `~socket.socket.listen ` method of the socket once it has been
1935
+ bound.
1932
1936
1933
1937
If *authenticate * is ``True `` (``False `` by default) or *authkey * is not
1934
1938
``None `` then digest authentication is used.
@@ -1946,8 +1950,8 @@ multiple connections at the same time.
1946
1950
.. method :: accept()
1947
1951
1948
1952
Accept a connection on the bound socket or named pipe of the listener
1949
- object and return a :class: `Connection ` object. If authentication is
1950
- attempted and fails, then
1953
+ object and return a :class: `~multiprocessing. Connection ` object. If
1954
+ authentication is attempted and fails, then
1951
1955
:exc: `~multiprocessing.AuthenticationError ` is raised.
1952
1956
1953
1957
.. method :: close()
@@ -1969,8 +1973,8 @@ multiple connections at the same time.
1969
1973
1970
1974
.. versionadded :: 3.3
1971
1975
Listener objects now support the context manager protocol -- see
1972
- :ref: `typecontextmanager `. :meth: `__enter__ ` returns the
1973
- listener object, and :meth: `__exit__ ` calls :meth: `close `.
1976
+ :ref: `typecontextmanager `. :meth: `~contextmanager. __enter__ ` returns the
1977
+ listener object, and :meth: ~contextmanager. `__exit__` calls :meth: `close `.
1974
1978
1975
1979
.. function :: wait(object_list, timeout=None)
1976
1980
@@ -2106,7 +2110,8 @@ an ``'AF_PIPE'`` address rather than an ``'AF_UNIX'`` address.
2106
2110
Authentication keys
2107
2111
~~~~~~~~~~~~~~~~~~~
2108
2112
2109
- When one uses :meth: `Connection.recv `, the data received is automatically
2113
+ When one uses :meth: `Connection.recv <multiprocessing.Connection.recv> `, the
2114
+ data received is automatically
2110
2115
unpickled. Unfortunately unpickling data from an untrusted source is a security
2111
2116
risk. Therefore :class: `Listener ` and :func: `Client ` use the :mod: `hmac ` module
2112
2117
to provide digest authentication.
@@ -2256,9 +2261,10 @@ Joining zombie processes
2256
2261
2257
2262
On Unix when a process finishes but has not been joined it becomes a zombie.
2258
2263
There should never be very many because each time a new process starts (or
2259
- :func: `active_children ` is called) all completed processes which have not
2260
- yet been joined will be joined. Also calling a finished process's
2261
- :meth: `Process.is_alive ` will join the process. Even so it is probably good
2264
+ :func: `~multiprocessing.active_children ` is called) all completed processes
2265
+ which have not yet been joined will be joined. Also calling a finished
2266
+ process's :meth: `Process.is_alive <multiprocessing.Process.is_alive> ` will
2267
+ join the process. Even so it is probably good
2262
2268
practice to explicitly join all the processes that you start.
2263
2269
2264
2270
Better to inherit than pickle/unpickle
@@ -2271,20 +2277,23 @@ Better to inherit than pickle/unpickle
2271
2277
2272
2278
Avoid terminating processes
2273
2279
2274
- Using the :meth: `Process.terminate ` method to stop a process is liable to
2280
+ Using the :meth: `Process.terminate <multiprocessing.Process.terminate> `
2281
+ method to stop a process is liable to
2275
2282
cause any shared resources (such as locks, semaphores, pipes and queues)
2276
2283
currently being used by the process to become broken or unavailable to other
2277
2284
processes.
2278
2285
2279
2286
Therefore it is probably best to only consider using
2280
- :meth: `Process.terminate ` on processes which never use any shared resources.
2287
+ :meth: `Process.terminate <multiprocessing.Process.terminate> ` on processes
2288
+ which never use any shared resources.
2281
2289
2282
2290
Joining processes that use queues
2283
2291
2284
2292
Bear in mind that a process that has put items in a queue will wait before
2285
2293
terminating until all the buffered items are fed by the "feeder" thread to
2286
2294
the underlying pipe. (The child process can call the
2287
- :meth: `Queue.cancel_join_thread ` method of the queue to avoid this behaviour.)
2295
+ :meth: `Queue.cancel_join_thread <multiprocessing.Queue.cancel_join_thread> `
2296
+ method of the queue to avoid this behaviour.)
2288
2297
2289
2298
This means that whenever you use a queue you need to make sure that all
2290
2299
items which have been put on the queue will eventually be removed before the
@@ -2361,7 +2370,7 @@ Beware of replacing :data:`sys.stdin` with a "file like object"
2361
2370
resulting in a bad file descriptor error, but introduces a potential danger
2362
2371
to applications which replace :func: `sys.stdin ` with a "file-like object"
2363
2372
with output buffering. This danger is that if multiple processes call
2364
- :func: ` close() ` on this file-like object, it could result in the same
2373
+ :meth: ` ~io.IOBase. close() ` on this file-like object, it could result in the same
2365
2374
data being flushed to the object multiple times, resulting in corruption.
2366
2375
2367
2376
If you write a file-like object and implement your own caching, you can
@@ -2390,14 +2399,16 @@ More picklability
2390
2399
as the ``target `` argument on Windows --- just define a function and use
2391
2400
that instead.
2392
2401
2393
- Also, if you subclass :class: `Process ` then make sure that instances will be
2394
- picklable when the :meth: `Process.start ` method is called.
2402
+ Also, if you subclass :class: `~multiprocessing.Process ` then make sure that
2403
+ instances will be picklable when the :meth: `Process.start
2404
+ <multiprocessing.Process.start> ` method is called.
2395
2405
2396
2406
Global variables
2397
2407
2398
2408
Bear in mind that if code run in a child process tries to access a global
2399
2409
variable, then the value it sees (if any) may not be the same as the value
2400
- in the parent process at the time that :meth: `Process.start ` was called.
2410
+ in the parent process at the time that :meth: `Process.start
2411
+ <multiprocessing.Process.start> ` was called.
2401
2412
2402
2413
However, global variables which are just module level constants cause no
2403
2414
problems.
@@ -2453,7 +2464,7 @@ Demonstration of how to create and use customized managers and proxies:
2453
2464
:language: python3
2454
2465
2455
2466
2456
- Using :class: `Pool `:
2467
+ Using :class: `~multiprocessing.pool. Pool `:
2457
2468
2458
2469
.. literalinclude :: ../includes/mp_pool.py
2459
2470
:language: python3
0 commit comments