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
SharedMemory crash when size is 0 #85516
Comments
On running this: shm = SharedMemory(create=True, size=0) Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/multiprocessing/shared_memory.py", line 111, in __init__
self._mmap = mmap.mmap(self._fd, size)
ValueError: cannot mmap an empty file
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg' Original exception was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/multiprocessing/shared_memory.py", line 111, in __init__
self._mmap = mmap.mmap(self._fd, size)
ValueError: cannot mmap an empty file
>>> shm = SharedMemory(create=True, size=0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/multiprocessing/shared_memory.py", line 111, in __init__
self._mmap = mmap.mmap(self._fd, size)
ValueError: cannot mmap an empty file
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/multiprocessing/shared_memory.py", line 111, in __init__
self._mmap = mmap.mmap(self._fd, size)
ValueError: cannot mmap an empty file This can be simply resolved by adding a check when size passed is 0, so that a shared memory segment is never created. if not size >= 0:
raise ValueError("'size' must be a positive integer") I believe this should be changed to: As zero is not a positive and integer and is causing problems. |
Python 3.10.0a0 Jul 23 2020, win32 (without patch) >>> from multiprocessing import shared_memory
>>> shm_a = shared_memory.SharedMemory(create=True, size=0)
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
shm_a = shared_memory.SharedMemory(create=True, size=0)
File "f:\dev\3x\lib\multiprocessing\shared_memory.py", line 129, in __init__
h_map = _winapi.CreateFileMapping(
OSError: [WinError 87] The parameter is incorrect: 'wnsm_4ab39616' After the patch, I get the value error. |
Hi, The patch aims to raise a value error, because before the patch also, ValueError was being raised in case size was negative. That's why I thought it would be correct behaviour if I raise ValueError in case size is 0. Do you mean to say, that OSError should be raise in the case size=0. |
Also, Linux created the shared memory with the passed name if size = 0, but threw error when it was being mapped to the process's virtual memory. Therefore, this scenario should be prevented before actually creating the shared memory segment in cases of Linux. |
No, I think ValueError on all systems is better. I have no idea what 'wnsm_4ab39616' is about other than something internal to Windows. It does not say what to do to correct the call. |
Thanks for the report and the PR, vinay0410! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: