STINNER Victor added the comment:

On the review, Antoine wrote:
"You should put this line earlier, as outputting a warning can release the 
GIL..."

I disagree. It's a deliberate choice to keep the socket open while logging the 
ResourceWarning.

Example:
---
import socket
import warnings

def show(msg):
    s = msg.source
    #s.close()
    if s.fileno() >= 0:
        print("socket open")
    else:
        print("socket closed")
    try:
        name = s.getsockname()
    except Exception as exc:
        name = str(exc)
    print("getsockname(): %r" % (name,))

warnings._showwarnmsg = show
s = socket.socket()
s = None
---

Output with  sock_finalize-2.patch:
---
socket open
getsockname(): ('0.0.0.0', 0)
---

If you uncomment the s.close() (or set sock_fd to -1 in the C code):
---
socket closed
getsockname(): '[Errno 9] Bad file descriptor'
---

IMHO it's ok to give access to socket methods in the warning logger.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26590>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to