Message262124
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. |
|
Date |
User |
Action |
Args |
2016-03-21 13:26:51 | vstinner | set | recipients:
+ vstinner, pitrou, serhiy.storchaka |
2016-03-21 13:26:51 | vstinner | set | messageid: <1458566811.77.0.320930509727.issue26590@psf.upfronthosting.co.za> |
2016-03-21 13:26:51 | vstinner | link | issue26590 messages |
2016-03-21 13:26:51 | vstinner | create | |
|