[issue36820] Captured exceptions are keeping user objects alive unnecessarily in the stdlib

2019-12-06 Thread miss-islington


miss-islington  added the comment:


New changeset 5ba591fa2c1f74c4a84372fb4ffc0b16863f1ad7 by Miss Islington (bot) 
in branch '3.7':
bpo-36820: Break unnecessary cycle in socket.py, codeop.py and dyld.py 
(GH-13135)
https://github.com/python/cpython/commit/5ba591fa2c1f74c4a84372fb4ffc0b16863f1ad7


--

___
Python tracker 

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



[issue36820] Captured exceptions are keeping user objects alive unnecessarily in the stdlib

2019-12-06 Thread miss-islington


miss-islington  added the comment:


New changeset 681285d052977e3a3a82ef665e788946fca1ac59 by Miss Islington (bot) 
in branch '3.8':
bpo-36820: Break unnecessary cycle in socket.py, codeop.py and dyld.py 
(GH-13135)
https://github.com/python/cpython/commit/681285d052977e3a3a82ef665e788946fca1ac59


--

___
Python tracker 

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



[issue36820] Captured exceptions are keeping user objects alive unnecessarily in the stdlib

2019-12-06 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

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



[issue36820] Captured exceptions are keeping user objects alive unnecessarily in the stdlib

2019-12-06 Thread miss-islington


Change by miss-islington :


--
pull_requests: +16965
pull_request: https://github.com/python/cpython/pull/17486

___
Python tracker 

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



[issue36820] Captured exceptions are keeping user objects alive unnecessarily in the stdlib

2019-12-06 Thread miss-islington


Change by miss-islington :


--
pull_requests: +16964
pull_request: https://github.com/python/cpython/pull/17485

___
Python tracker 

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



[issue36820] Captured exceptions are keeping user objects alive unnecessarily in the stdlib

2019-12-06 Thread miss-islington


miss-islington  added the comment:


New changeset b64334cb93d0ddbb551c8cd712942bab2fc72772 by Miss Islington (bot) 
(Mario Corchero) in branch 'master':
bpo-36820: Break unnecessary cycle in socket.py, codeop.py and dyld.py 
(GH-13135)
https://github.com/python/cpython/commit/b64334cb93d0ddbb551c8cd712942bab2fc72772


--
nosy: +miss-islington

___
Python tracker 

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



[issue36820] Captured exceptions are keeping user objects alive unnecessarily in the stdlib

2019-05-06 Thread Eric N. Vander Weele


Change by Eric N. Vander Weele :


--
nosy: +ericvw

___
Python tracker 

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



[issue36820] Captured exceptions are keeping user objects alive unnecessarily in the stdlib

2019-05-06 Thread Barry A. Warsaw


Change by Barry A. Warsaw :


--
nosy: +barry

___
Python tracker 

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



[issue36820] Captured exceptions are keeping user objects alive unnecessarily in the stdlib

2019-05-06 Thread Mario Corchero


Change by Mario Corchero :


--
keywords: +patch
pull_requests: +13048
stage:  -> patch review

___
Python tracker 

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



[issue36820] Captured exceptions are keeping user objects alive unnecessarily in the stdlib

2019-05-06 Thread Mario Corchero


New submission from Mario Corchero :

There are multiple places in the standard library where the code captures an 
exception and reraises it later (outside of the original except).

This is known to cause a cycle as saving the exception has a traceback that 
eventually points back to the exception, but it is especially problematic as it 
keeps alive the objects that the user has as well.

This can be reproduced with the following example:

```
import weakref

class A: pass

ref = None

def x():
global ref
cool_var = A()
ref = weakref.ref(cool_var)
assert ref()
try:
1/0
except Exception as e:
ee = e

try:
x()
except Exception:
pass

print(ref())
assert ref() is None
```

There are places in the standard library that try to get around this. See 
https://github.com/python/cpython/commit/acb9fa79fa6453c2bbe3ccfc9cad2837feb90093
 as an example. This change did not include the exception path though, when the 
`err` variable is raised, the issue is still present.

This issue is to fix the instances found in socket.py, codeop.py and dyld.py. 
By either setting the variable to None to remove the name or if it needs to be 
reraised by using a finally to delete it. This is basically the same that a try 
except would do, which automagically adds a finally to delete the local name 
used in the `except X as y`.
There was a discussion with twouters,pablogsal,barry about potentially adding 
something extra to the exception handling to try to clean this up but it was 
suggested the best approach is for the user to handle it and maybe a linter to 
potentially flag it, as there might also be multiple references to the 
exception being captured. It was also proposed to just change the situations 
where this happens in the standard library to remove the name if possible.

Note that eventually those objects will just be collected by the gc, it is just 
an improvement.

I'm preparing a PR for those three modules.

--
components: Library (Lib)
messages: 341620
nosy: mariocj89, pablogsal, twouters
priority: low
severity: normal
status: open
title: Captured exceptions are keeping user objects alive unnecessarily in the 
stdlib
type: enhancement
versions: Python 3.8

___
Python tracker 

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