-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-35813: Tests and docs for shared_memory #11816
Changes from 1 commit
720a8ea
29a7f80
c56e29c
c36de70
3c89c7c
5f4ba8f
f9aaa11
2377cfd
6bfa560
eaf7888
e166ed9
0f18511
a097dbb
7c65017
da7731d
242a5e9
7bdfbbb
eec4bb1
1076567
0be0531
1e5341e
a5800a9
34f1e9a
9846290
1f9bbf2
69dd8a9
8cf9ba3
594140a
395709b
aa4a887
885592b
9001b76
5848ec4
6ff8eed
06620e2
868b83d
9d83b06
715ded9
6878533
0d3d06f
05e26dd
7a3c7e5
caf0a5d
12c097d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ This module provides a class, :class:`SharedMemory`, for the allocation | |
and management of shared memory to be accessed by one or more processes | ||
on a multicore or SMP machine. To assist with the life-cycle management | ||
of shared memory especially across distinct processes, a | ||
:class:`multiprocessing.managers.BaseManager` subclass, | ||
:class:`~multiprocessing.managers.BaseManager` subclass, | ||
:class:`SharedMemoryManager`, is also provided. | ||
|
||
In this module, shared memory refers to "System V style" shared memory blocks | ||
|
@@ -85,7 +85,7 @@ copying of data. | |
inside the shared memory block after ``unlink()`` has been called may | ||
result in memory access errors. Note: the last process relinquishing | ||
its hold on a shared memory block may call ``unlink()`` and | ||
``close()`` in either order. | ||
:meth:`close()` in either order. | ||
|
||
.. attribute:: buf | ||
|
||
|
@@ -180,16 +180,17 @@ two distinct Python shells:: | |
|
||
.. class:: SharedMemoryManager([address[, authkey]]) | ||
|
||
A subclass of :class:`multiprocessing.managers.BaseManager` which can be | ||
A subclass of :class:`~multiprocessing.managers.BaseManager` which can be | ||
used for the management of shared memory blocks across processes. | ||
|
||
Instantiation of a :class:`SharedMemoryManager` causes a new process to | ||
be started. This new process's sole purpose is to manage the life cycle | ||
A call to :meth:`~multiprocessing.managers.BaseManager.start` on a | ||
:class:`SharedMemoryManager` instance causes a new process to be started. | ||
This new process's sole purpose is to manage the life cycle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After double-checking with a technical editor just now, I have been assured that either is correct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great! |
||
of all shared memory blocks created through it. To trigger the release | ||
of all shared memory blocks managed by that process, call | ||
:func:`multiprocessing.managers.BaseManager.shutdown()` on the instance. | ||
This triggers a :func:`SharedMemory.unlink()` call on all of the | ||
:class:`SharedMemory` instances managed by that process and then | ||
:meth:`~multiprocessing.managers.BaseManager.shutdown()` on the instance. | ||
This triggers a :meth:`SharedMemory.unlink()` call on all of the | ||
:class:`SharedMemory` objects managed by that process and then | ||
stops the process itself. By creating ``SharedMemory`` instances | ||
through a ``SharedMemoryManager``, we avoid the need to manually track | ||
and trigger the freeing of shared memory resources. | ||
|
@@ -315,13 +316,13 @@ shared memory blocks created using that manager are all released when the | |
|
||
.. method:: index(value) | ||
|
||
Returns first index position of ``value``. Raises ValueError if | ||
Returns first index position of ``value``. Raises :exc:`ValueError` if | ||
``value`` is not present. | ||
|
||
.. attribute:: format | ||
|
||
Read-only attribute containing the struct packing format used by all | ||
currently stored values. | ||
Read-only attribute containing the :mod:`struct` packing format used by | ||
all currently stored values. | ||
|
||
.. attribute:: shm | ||
|
||
|
@@ -340,7 +341,7 @@ instance: | |
>>> a[2] = -78.5 | ||
>>> a[2] | ||
-78.5 | ||
>>> a[2] = 'dry ice' # Changing data types is supported as well. | ||
>>> a[2] = 'dry ice' # Changing data types is supported as well | ||
>>> a[2] | ||
'dry ice' | ||
>>> a[2] = 'larger than previously allocated storage space' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm... what's the point of having both
close
andunlink
? Why not simply havingclose()
also destroy the memory blocks?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After all instances have called
close()
, there are still reasons to potentially want to have a shared memory block persist. An existing technique that some services use to preserve data even when the service dies unexpectedly is to store critical data in a shared memory block with an established name -- when the service restarts, it looks for the shared memory to still be there by name, thereby reducing the startup time of the service. Other use cases likely helped motivate the mentality behind the Windows implementation of shared memory which always preserves the shared memory block until the last process with a handle on it terminates -- Windows offers no way to perform anunlink()
action ahead of time. Closest thing you can do on Windows is truncate its size to near zero but even that might not trigger a partial release of memory space. Across platforms, the common mentality and conscious design is to preserve shared memory until its release is explicitly demanded.