@@ -107,6 +107,8 @@ Contexts and start methods
107107Depending on the platform, :mod: `multiprocessing ` supports three ways
108108to start a process. These *start methods * are
109109
110+ .. _multiprocessing-start-method-spawn :
111+
110112 *spawn *
111113 The parent process starts a fresh Python interpreter process. The
112114 child process will only inherit those resources necessary to run
@@ -117,6 +119,8 @@ to start a process. These *start methods* are
117119
118120 Available on POSIX and Windows platforms. The default on Windows and macOS.
119121
122+ .. _multiprocessing-start-method-fork :
123+
120124 *fork *
121125 The parent process uses :func: `os.fork ` to fork the Python
122126 interpreter. The child process, when it begins, is effectively
@@ -137,6 +141,8 @@ to start a process. These *start methods* are
137141 raise a :exc: `DeprecationWarning `. Use a different start method.
138142 See the :func: `os.fork ` documentation for further explanation.
139143
144+ .. _multiprocessing-start-method-forkserver :
145+
140146 *forkserver *
141147 When the program starts and selects the *forkserver * start method,
142148 a server process is spawned. From then on, whenever a new process
@@ -374,35 +380,40 @@ However, if you really do need to use some shared data then
374380 proxies.
375381
376382 A manager returned by :func: `Manager ` will support types
377- :class: `list `, :class: `dict `, :class: `~managers.Namespace `, :class: `Lock `,
383+ :class: `list `, :class: `dict `, :class: `set `, :class: ` ~managers.Namespace `, :class: `Lock `,
378384 :class: `RLock `, :class: `Semaphore `, :class: `BoundedSemaphore `,
379385 :class: `Condition `, :class: `Event `, :class: `Barrier `,
380386 :class: `Queue `, :class: `Value ` and :class: `Array `. For example, ::
381387
382388 from multiprocessing import Process, Manager
383389
384- def f(d, l):
390+ def f(d, l, s ):
385391 d[1] = '1'
386392 d['2'] = 2
387393 d[0.25] = None
388394 l.reverse()
395+ s.add('a')
396+ s.add('b')
389397
390398 if __name__ == '__main__':
391399 with Manager() as manager:
392400 d = manager.dict()
393401 l = manager.list(range(10))
402+ s = manager.set()
394403
395- p = Process(target=f, args=(d, l))
404+ p = Process(target=f, args=(d, l, s ))
396405 p.start()
397406 p.join()
398407
399408 print(d)
400409 print(l)
410+ print(s)
401411
402412 will print ::
403413
404414 {0.25: None, 1: '1', '2': 2}
405415 [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
416+ {'a', 'b'}
406417
407418 Server process managers are more flexible than using shared memory objects
408419 because they can be made to support arbitrary object types. Also, a single
@@ -1936,6 +1947,15 @@ their parent process exits. The manager classes are defined in the
19361947
19371948 Create a shared :class: `list ` object and return a proxy for it.
19381949
1950+ .. method :: set()
1951+ set(sequence)
1952+ set(mapping)
1953+
1954+ Create a shared :class: `set ` object and return a proxy for it.
1955+
1956+ .. versionadded :: next
1957+ :class: `set ` support was added.
1958+
19391959 .. versionchanged :: 3.6
19401960 Shared objects are capable of being nested. For example, a shared
19411961 container object such as a shared list can contain other shared objects
@@ -2987,6 +3007,9 @@ Beware of replacing :data:`sys.stdin` with a "file like object"
29873007
29883008 For more information, see :issue: `5155 `, :issue: `5313 ` and :issue: `5331 `
29893009
3010+ .. _multiprocessing-programming-spawn :
3011+ .. _multiprocessing-programming-forkserver :
3012+
29903013The *spawn * and *forkserver * start methods
29913014^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29923015
0 commit comments