[issue38119] resource tracker destroys shared memory segments when other processes should still have valid access

2021-03-08 Thread Álvaro Justen

Álvaro Justen  added the comment:

Based on changes at https://github.com/python/cpython/pull/15989 I've 
monkey-patched `multiprocessing.resource_tracker` so my current applications 
(running on Python 3.9.2) won't be affected. The code may be useful to others 
while the PR is not merged and we don't have a new release - you just need to 
call the `remove_shm_from_resource_tracker` function inside each Process target 
function.

- >8 -
from multiprocessing import resource_tracker


def remove_shm_from_resource_tracker():
"""Monkey-patch multiprocessing.resource_tracker so SharedMemory won't be 
tracked

More details at: https://bugs.python.org/issue38119
"""

def fix_register(name, rtype):
if rtype == "shared_memory":
return
return resource_tracker._resource_tracker.register(self, name, rtype)
resource_tracker.register = fix_register

def fix_unregister(name, rtype):
if rtype == "shared_memory":
return
return resource_tracker._resource_tracker.unregister(self, name, rtype)
resource_tracker.unregister = fix_unregister

if "shared_memory" in resource_tracker._CLEANUP_FUNCS:
del resource_tracker._CLEANUP_FUNCS["shared_memory"]
- 8< -

There's a working example in attached file `mprt_monkeypatch.py` (if you 
comment the function calls on lines 28 and 37 the warnings will be shown).

--
nosy: +turicas
Added file: https://bugs.python.org/file49859/mprt_monkeypatch.py

___
Python tracker 
<https://bugs.python.org/issue38119>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34539] namedtuple's exec() throws segmentation fault

2018-08-30 Thread Álvaro Justen

Álvaro Justen  added the comment:

Yes, I think it was fixed in https://bugs.python.org/issue34087 (didn't see the 
commits), I just wanted to report it because I don't know if a test for this 
specific case is needed (the other bug is not related to namedtuples).

--

___
Python tracker 
<https://bugs.python.org/issue34539>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34539] namedtuple's exec() throws segmentation fault

2018-08-29 Thread Álvaro Justen

Álvaro Justen  added the comment:

I've cloned the cpython git repository and made fresh builds here:

On v.3.6.6 (4cf1f54eb764f856fda5a394d8598c0c90d69d77) it works:

$ git checkout v3.6.6 && ./configure && make && ./python --version && 
./python namedtuple_bug.py
[...compilation lines supressed...]
Python 3.6.6

On the v.3.7.0 (1bf9cc509326bc42cd8cb1650eb9bf64550d817e) it segfaults:

$ git checkout v3.7.0 && make clean && ./configure && make && ./python 
--version && ./python namedtuple_bug.py
[...compilation lines supressed...]
Python 3.7.0
Segmentation fault

On the most recent 3.7 branch (65ef7425a32ee411d8047a4fad0fc6bb9ff733b1) it 
works:

$ git checkout 3.7 && make clean && ./configure && make && ./python 
--version && ./python namedtuple_bug.py
[...compilation lines supressed...]
Python 3.7.0+

On master branch (2c8ddcf4f14f3e4c87a6fe6678ab5ad09130c6ab) it also works:

$ git checkout master && make clean && ./configure && make && ./python 
--version && ./python namedtuple_bug.py
[...compilation lines supressed...]
Python 3.8.0a0

Note: I've tried to add a `print('works!')` at the end of the script, so we can 
see the result when it does not segfault, but adding this actually make it 
works on all versions; removing this line has the behaviour reported above.

--

___
Python tracker 
<https://bugs.python.org/issue34539>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34539] namedtuple's exec() throws segmentation fault

2018-08-28 Thread Álvaro Justen

New submission from Álvaro Justen :

I was working on a library called rows[https://github.com/turicas/rows] when a 
segmentation fault was thrown in the moment I've tried to read a CSV file. 
Since this part of the code is implemented completely in Python, I thought it 
could be a bug in Python itself.
Investigating the code I found it was faulting at exec()'s line inside 
namedtuple code (Lib/collections/__init__.py). After some time testing, I've 
came up with this piece of code to reproduce it:

```
try:
float('áxxx')
except:
from collections import namedtuple
namedtuple('T', 'f')
```

The code works if I:
- Run passing `PYTHONMALLOC=debug`
- Place 'from collections import namedtuple' into the first line
- Remove any char from the string in the 'float(...)' line
- Remove the 'á' from the string in the 'float(...)' line

I've tested the code on Python 3.6.6, 3.7.0, 3.7-dev and 3.8-dev (versions 
installed using pyenv on a Debian GNU/Linux machine) and the problem happened 
only in 3.7.0.
This issue seems to be related to https://bugs.python.org/issue34087 but I 
preferred to create a new one since I don't know if there are automated tests 
for this specific case.

--
components: Library (Lib)
files: namedtuple_bug.py
messages: 324300
nosy: turicas
priority: normal
severity: normal
status: open
title: namedtuple's exec() throws segmentation fault
type: crash
versions: Python 3.7
Added file: https://bugs.python.org/file47772/namedtuple_bug.py

___
Python tracker 
<https://bugs.python.org/issue34539>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com