-
-
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
…dMemory.size.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,17 +112,31 @@ def __init__(self, name, flags=None, mode=384, size=0, read_only=False): | |
raise FileExistsError(name) | ||
|
||
self._mmap = mmap.mmap(-1, size, tagname=name) | ||
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. Same here (see my previous comment). 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. Same comment for me too (ref the prior comment/conversation). |
||
self.buf = memoryview(self._mmap) | ||
self._buf = memoryview(self._mmap) | ||
self.name = name | ||
self.mode = mode | ||
self.size = size | ||
self._size = size | ||
|
||
@property | ||
def size(self): | ||
"Size in bytes." | ||
return self._size | ||
|
||
@property | ||
def buf(self): | ||
"A memoryview of contents of the shared memory block." | ||
return self._buf | ||
|
||
def __repr__(self): | ||
return f'{self.__class__.__name__}({self.name!r}, size={self.size})' | ||
|
||
def close(self): | ||
self.buf.release() | ||
self._mmap.close() | ||
if self._buf is not None: | ||
self._buf.release() | ||
self._buf = None | ||
if self._mmap is not None: | ||
self._mmap.close() | ||
self._mmap = None | ||
|
||
def unlink(self): | ||
"""Windows ensures that destruction of the last reference to this | ||
|
@@ -157,7 +171,7 @@ class PosixSharedMemory: | |
fd = -1 | ||
name = None | ||
_mmap = None | ||
buf = None | ||
_buf = None | ||
|
||
def __init__(self, name, flags=None, mode=384, size=0, read_only=False): | ||
if name and (flags is None): | ||
|
@@ -185,7 +199,7 @@ def __init__(self, name, flags=None, mode=384, size=0, read_only=False): | |
self.unlink() | ||
raise | ||
self._mmap = mmap.mmap(self.fd, self.size) | ||
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. This is not my territory, so take it with a grain of salt. I see that 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. It is a good point. With the simpler API introduced in commit 0d3d06f, we constrain the supported behaviors to no longer offer these sorts of control. The behavior of mmap seems to have some inconsistencies of its own across different platforms when trying to specify such modes of access -- I think this only encourages me to believe we have made the right choice with the simplified API. |
||
self.buf = memoryview(self._mmap) | ||
self._buf = memoryview(self._mmap) | ||
|
||
@property | ||
def size(self): | ||
|
@@ -195,6 +209,11 @@ def size(self): | |
else: | ||
return 0 | ||
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. Mmm... since you make a 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. In commit 0d3d06f, I have eliminated the use of |
||
|
||
@property | ||
def buf(self): | ||
"A memoryview of contents of the shared memory block." | ||
return self._buf | ||
|
||
def _open_retry(self): | ||
# generate a random name, open, retry if it exists | ||
while True: | ||
|
@@ -215,9 +234,9 @@ def unlink(self): | |
_posixshmem.shm_unlink(self.name) | ||
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. shouldn't 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. In the same sense that 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. Clear enough. Thanks. 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. On a second thought... if 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. If one process calls The docs currently say that if |
||
|
||
def close(self): | ||
if self.buf is not None: | ||
self.buf.release() | ||
self.buf = None | ||
if self._buf is not None: | ||
self._buf.release() | ||
self._buf = None | ||
if self._mmap is not None: | ||
self._mmap.close() | ||
self._mmap = None | ||
|
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.
You could enrich the exception:
Result:
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.
Good point -- changed in 6878533.