10000 gh-90556: add SharedMemory.rename on multiprocessing.shared_memory by aisk · Pull Request #132130 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-90556: add SharedMemory.rename on multiprocessing.shared_memory #132130

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

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4ecc7bd
posixshmem module shm_rename freebsd support.
devnexen Jan 16, 2022
1336f8c
update shared_memory library
devnexen Jan 16, 2022
d11ff82
doc update
devnexen Jan 16, 2022
13734b6
📜🤖 Added by blurb_it.
blurb-it[bot] Jan 17, 2022
c82d4db
Merge remote-tracking branch 'origin/main' into shm_rename
aisk Mar 29, 2025
69d583f
Update generated files
aisk Mar 29, 2025
83d63f4
Update by review
aisk Mar 29, 2025
ba0e6d0
Improve document by introduce more RST markers
aisk Mar 29, 2025
514ed3d
Add test
aisk Apr 5, 2025
810e765
update quote in .in file
aisk Apr 5, 2025
fa45c2e
regen-config
aisk Apr 5, 2025
bea3158
Merge branch 'main' into shm_rename
aisk Apr 5, 2025
ca0714b
Fix news entry
aisk Apr 5, 2025
b3ec978
Fix docs
aisk Apr 5, 2025
778e646
fix news entry
aisk Apr 5, 2025
7e3242c
fix news entry
aisk Apr 5, 2025
6ec2152
Update Lib/multiprocessing/shared_memory.py
aisk Apr 6, 2025
8109775
Update Doc/library/multiprocessing.shared_memory.rst
aisk Apr 6, 2025
8e86d21
Update Doc/library/multiprocessing.shared_memory.rst
aisk Apr 6, 2025
ef3b5ce
Update Misc/NEWS.d/next/Library/2022-01-17-20-03-56.bpo-46398.FATeqM.rst
aisk Apr 6, 2025
86debb3
Update Doc/library/multiprocessing.shared_memory.rst
aisk Apr 6, 2025
cb181b0
Remove whitespace in empty line
aisk Apr 6, 2025
f6f8312
Define the rename method conditionally
aisk Apr 6, 2025
1cc08d7
Fix test on Windows
aisk Apr 6, 2025
d77049c
Fix codes on Windows
aisk Apr 6, 2025
416c6d8
Move constants
aisk Apr 6, 2025
620da83
Update document
aisk Apr 6, 2025
4993685
Fix indent in document
aisk Apr 6, 2025
8adc394
Add more tests
aisk Apr 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
📜🤖 Added by blurb_it.
  • Loading branch information
blurb-it[bot] authored and devnexen committed Feb 24, 2024
commit 13734b63a3f38fc4cf79a92e2503f20eee3c6fef
13 changes: 4 additions & 9 deletions Lib/multiprocessing/shared_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,14 @@ def rename(self, newname, flags = 0):
With the SHM_RENAME_NOREPLACE flag, an error will be returned
if the new name exists.
"""
if platform.system() != "FreeBSD":
if !platform.hasattr("shm_rename"):
raise OSError("Unsupported operation on this platform")

if newname:
newname = "/" + newname if self._prepend_leading_slash else newname
r = _posixshmem.shm_rename(self._name, newname, flags)
if r == None:
from .resource_tracker import unregister, register
unregister(self._name, "shared_memory")
self._name = newname
register(self._name, "shared_memory")
return True

self._fd = _posixshmem.shm_rename(self._name, newname, flags)
self._name = newname
return True
return False


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add :method:`rename` to the `multiprocessing.shared_memory` library for FreeBSD.
47 changes: 13 additions & 34 deletions Modules/_multiprocessing/clinic/posixshmem.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions Modules/_multiprocessing/posixshmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ _posixshmem.shm_rename
path_from: unicode
path_to: unicode
flags: int
/

Rename a shared memory object.

Remove a shared memory object and relink to another path
Remove a shared memory object and relink to another path.
By default, if the destination path already exist, it will be unlinked.
With the SHM_RENAME_EXCHANGE flag, source and destination paths
will be exchanged.
Expand All @@ -86,17 +87,17 @@ if the destination alredady exists.

[clinic start generated code]*/

static PyObject *
static int
_posixshmem_shm_rename_impl(PyObject *module, PyObject *path_from,
PyObject *path_to, int flags)
/*[clinic end generated code: output=a9101f606826ad30 input=e32a44cee3e0326e]*/
/*[clinic end generated code: output=a9101f606826ad30 input=0373bfc9c491e123]*/
{
int rv;
int async_err = 0;
const char *from = PyUnicode_AsUTF8(path_from);
const char *to = PyUnicode_AsUTF8(path_to);
const char *from = PyUnicode_AsUTF8AndSize(path_from, NULL);
const char *to = PyUnicode_AsUTF8AndSize(path_to, NULL);
if (from == NULL || to == NULL) {
return NULL;
return -1;
}
do {
Py_BEGIN_ALLOW_THREADS
Expand All @@ -107,10 +108,10 @@ _posixshmem_shm_rename_impl(PyObject *module, PyObject *path_from,
if (rv < 0) {
if (!async_err)
PyErr_SetFromErrnoWithFilenameObjects(PyExc_OSError, path_from, path_to);
return NULL;
return -1;
}

Py_RETURN_NONE;
return rv;
}
#endif /* HAVE_SHM_RENAME */

Expand Down
1 change: 0 additions & 1 deletion Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -17297,7 +17297,6 @@ all_ins(PyObject *m)
#endif
#endif /* HAVE_SHM_RENAME */

#ifdef HAVE_EVENTFD
#if defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)
if (PyModule_AddIntMacro(m, EFD_CLOEXEC)) return -1;
#ifdef EFD_NONBLOCK
Expand Down
0