[New-bugs-announce] [issue46888] SharedMemory.close() destroys memory

Ronny Rentner report at bugs.python.org
Tue Mar 1 06:39:08 EST 2022


New submission from Ronny Rentner <python at ronny-rentner.de>:

According to https://docs.python.org/3/library/multiprocessing.shared_memory.html#multiprocessing.shared_memory.SharedMemory.close if I call close() on a shared memory, it shall not be destroyed.

Unfortunately this is only true for Linux but not for Windows.

I've tested this in a Windows VM on VirtualBox like this:

```
Python 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import multiprocessing.shared_memory
>>> creator = multiprocessing.shared_memory.SharedMemory(create=True, name='mymemory', size=10000)
>>> creator.buf[0] = 1
>>> creator.buf[0]
1
>>> # According to  close() is supposed to not destroy 'mymemory' but it does destroy it.
>>> creator.close()
>>>
>>> user = multiprocessing.shared_memory.SharedMemory(name='mymemory')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\multiprocessing\shared_memory.py", line 161, in __init__
    h_map = _winapi.OpenFileMapping(
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'mymemory'
>>> # Shared memory was destroyed by close()
```

----------
components: Windows
messages: 414258
nosy: paul.moore, ronny-rentner, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: SharedMemory.close() destroys memory
type: behavior
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46888>
_______________________________________


More information about the New-bugs-announce mailing list