@@ -38,7 +38,8 @@ copying of data.
38
38
39
39
.. class :: SharedMemory(name=None, create=False, size=0, *, track=True)
40
40
41
- Creates a new shared memory block or attaches to an existing shared
41
+ Create an instance of the :class: `!SharedMemory ` class for either
42
+ creating a new shared memory block or attaching to an existing shared
42
43
memory block. Each shared memory block is assigned a unique name.
43
44
In this way, one process can create a shared memory block with a
44
45
particular name and a different process can attach to that same shared
@@ -51,41 +52,48 @@ copying of data.
51
52
When a shared memory block is no longer needed by any process, the
52
53
:meth: `unlink ` method should be called to ensure proper cleanup.
53
54
54
- *name * is the unique name for the requested shared memory, specified as
55
- a string. When creating a new shared memory block, if ``None `` (the
56
- default) is supplied for the name, a novel name will be generated.
57
-
58
- *create * controls whether a new shared memory block is created (``True ``)
59
- or an existing shared memory block is attached (``False ``).
60
-
61
- *size * specifies the requested number of bytes when creating a new shared
62
- memory block. Because some platforms choose to allocate chunks of memory
63
- based upon that platform's memory page size, the exact size of the shared
64
- memory block may be larger or equal to the size requested. When attaching
65
- to an existing shared memory block, the *size * parameter is ignored.
66
-
67
- *track *, when enabled, registers the shared memory block with a resource
68
- tracker process on platforms where the OS does not do this automatically.
69
- The resource tracker ensures proper cleanup of the shared memory even
70
- if all other processes with access to the memory exit without doing so.
71
- Python processes created from a common ancestor using :mod: `multiprocessing `
72
- facilities share a single resource tracker process, and the lifetime of
73
- shared memory segments is handled automatically among these processes.
74
- Python processes created in any other way will receive their own
75
- resource tracker when accessing shared memory with *track * enabled.
76
- This will cause the shared memory to be deleted by the resource tracker
77
- of the first process that terminates.
78
- To avoid this issue, users of :mod: `subprocess ` or standalone Python
79
- processes should set *track * to ``False `` when there is already another
80
- process in place that does the bookkeeping.
81
- *track * is ignored on Windows, which has its own tracking and
82
- automatically deletes shared memory when all handles to it have been closed.
83
-
84
- .. versionchanged :: 3.13 Added *track* parameter.
55
+ :param name:
56
+ The unique name for the requested shared memory, specified as a string.
57
+ When creating a new shared memory block, if ``None `` (the default)
58
+ is supplied for the name, a novel name will be generated.
59
+ :type name: str | None
60
+
61
+ :param bool create:
62
+ Control whether a new shared memory block is created (``True ``)
63
+ or an existing shared memory block is attached (``False ``).
64
+
65
+ :param int size:
66
+ The requested number of bytes when creating a new shared memory block.
67
+ Because some platforms choose to allocate chunks of memory
68
+ based upon that platform's memory page size, the exact size of the shared
69
+ memory block may be larger or equal to the size requested.
70
+ When attaching to an existing shared memory block,
71
+ the *size * parameter is ignored.
72
+
73
+ :param bool track:
74
+ When ``True ``, register the shared memory block with a resource
75
+ tracker process on platforms where the OS does not do this automatically.
76
+ The resource tracker ensures proper cleanup of the shared memory even
77
+ if all other processes with access to the memory exit without doing so.
78
+ Python processes created from a common ancestor using :mod: `multiprocessing `
79
+ facilities share a single resource tracker process, and the lifetime of
80
+ shared memory segments is handled automatically among these processes.
81
+ Python processes created in any other way will receive their own
82
+ resource tracker when accessing shared memory with *track * enabled.
83
+ This will cause the shared memory to be deleted by the resource tracker
84
+ of the first process that terminates.
85
+ To avoid this issue, users of :mod: `subprocess ` or standalone Python
86
+ processes should set *track * to ``False `` when there is already another
87
+ process in place that does the bookkeeping.
88
+ *track * is ignored on Windows, which has its own tracking and
89
+ automatically deletes shared memory when all handles to it have been closed.
90
+
91
+ .. versionadded :: 3.13
92
+ The *track * parameter.
85
93
86
94
.. method :: close()
87
95
88
- Closes the file descriptor/handle to the shared memory from this
96
+ Close the file descriptor/handle to the shared memory from this
89
97
instance. :meth: `close ` should be called once access to the shared
90
98
memory block from this instance is no longer needed. Depending
91
99
on operating system, the underlying memory may or may not be freed
@@ -94,7 +102,7 @@ copying of data.
94
102
95
103
.. method :: unlink()
96
104
97
- Deletes the underlying shared memory block. This should be called only
105
+ Delete the underlying shared memory block. This should be called only
98
106
once per shared memory block regardless of the number of handles to it,
99
107
even in other processes.
100
108
:meth: `unlink ` and :meth: `close ` can be called in any order, but
@@ -277,7 +285,7 @@ finishes execution.
277
285
278
286
.. class :: ShareableList(sequence=None, *, name=None)
279
287
280
- Provides a mutable list-like object where all values stored within are
288
+ Provide a mutable list-like object where all values stored within are
281
289
stored in a shared memory block.
282
290
This constrains storable values to the following built-in data types:
283
291
@@ -334,12 +342,12 @@ finishes execution.
334
342
335
343
.. method :: count(value)
336
344
337
- Returns the number of occurrences of *value *.
345
+ Return the number of occurrences of *value *.
338
346
339
347
.. method :: index(value)
340
348
341
- Returns first index position of *value *. Raises :exc: ` ValueError ` if
342
- *value * is not present.
349
+ Return first index position of *value *.
350
+ Raise :exc: ` ValueError ` if *value * is not present.
343
351
344
352
.. attribute :: format
345
353
0 commit comments