[issue26590] socket destructor: implement finalizer

2016-03-21 Thread Roundup Robot
Roundup Robot added the comment: New changeset a97d317dec85 by Victor Stinner in branch 'default': Fix test_ssl.test_refcycle() https://hg.python.org/cpython/rev/a97d317dec85 -- ___ Python tracker _

[issue26590] socket destructor: implement finalizer

2016-03-21 Thread STINNER Victor
STINNER Victor added the comment: Thanks for the review. I pushed my change. -- resolution: -> fixed status: open -> closed ___ Python tracker ___ __

[issue26590] socket destructor: implement finalizer

2016-03-21 Thread Roundup Robot
Roundup Robot added the comment: New changeset 46329eec5515 by Victor Stinner in branch 'default': Add socket finalizer https://hg.python.org/cpython/rev/46329eec5515 -- nosy: +python-dev ___ Python tracker ___

[issue26590] socket destructor: implement finalizer

2016-03-21 Thread Antoine Pitrou
Antoine Pitrou added the comment: Yes, it looks good to me. -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue26590] socket destructor: implement finalizer

2016-03-21 Thread STINNER Victor
STINNER Victor added the comment: > Oh, I see. Perhaps add a comment then? Sure, done. Does it look better now? -- Added file: http://bugs.python.org/file42233/sock_finalize-3.patch ___ Python tracker ___

[issue26590] socket destructor: implement finalizer

2016-03-21 Thread Antoine Pitrou
Antoine Pitrou added the comment: Oh, I see. Perhaps add a comment then? -- ___ Python tracker ___ ___ Python-bugs-list mailing list U

[issue26590] socket destructor: implement finalizer

2016-03-21 Thread STINNER Victor
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 sh

[issue26590] socket destructor: implement finalizer

2016-03-21 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- nosy: +serhiy.storchaka ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https:

[issue26590] socket destructor: implement finalizer

2016-03-21 Thread STINNER Victor
STINNER Victor added the comment: > Now that there is a safe finalizer, I wonder if it should release the GIL, as > in sock_close(). Ah yes, good idea. I updated my patch. I also changed the change to begin by setting the sock_fd attribute to -1, before closing the socket (since the GIL is no

[issue26590] socket destructor: implement finalizer

2016-03-21 Thread Antoine Pitrou
Antoine Pitrou added the comment: Now that there is a safe finalizer, I wonder if it should release the GIL, as in sock_close(). -- ___ Python tracker ___ __

[issue26590] socket destructor: implement finalizer

2016-03-19 Thread Antoine Pitrou
Antoine Pitrou added the comment: Le 19/03/2016 14:07, STINNER Victor a écrit : > > Example: > --- > import socket > s=socket.socket() > s=None > --- > > With this code, sock_finalize() is called before sock_dealloc(): > > #0 sock_finalize (s=0x70730c28) at > /home/haypo/prog/python/defau

[issue26590] socket destructor: implement finalizer

2016-03-19 Thread STINNER Victor
STINNER Victor added the comment: Antoine Pitrou added the comment: > Ah, that's probably because socket.socket is a Python subclass. > What happens if you use _socket.socket directly instead? Oh, I forgot this sublte implementation detail, _socket.socket base class vs socket.socket sublcass. E

[issue26590] socket destructor: implement finalizer

2016-03-19 Thread STINNER Victor
STINNER Victor added the comment: @Antoine: Since you wrote the PEP 442, would you reviewing sock_finalize.patch? I'm only interested to modify Python 3.6, the bug was only trigerred when I changed the code to log a warning. Before, the socket object was not passed to the warning logger so it

[issue26590] socket destructor: implement finalizer

2016-03-19 Thread STINNER Victor
STINNER Victor added the comment: 2016-03-19 11:05 GMT+01:00 Antoine Pitrou : > sock_finalize() is only called explicitly if there is a reference cycle. This > is why sock_dealloc() has to call it. I'm fine with keeping sock_dealloc() to call sock_finalize(), but I would like to understand. Ex

[issue26590] socket destructor: implement finalizer

2016-03-19 Thread Antoine Pitrou
Antoine Pitrou added the comment: sock_finalize() is only called explicitly if there is a reference cycle. This is why sock_dealloc() has to call it. -- ___ Python tracker ___ _

[issue26590] socket destructor: implement finalizer

2016-03-19 Thread STINNER Victor
STINNER Victor added the comment: Attached patch adds a finalizer to _socket.socket() and use PyErr_ResourceWarning() to log the traceback where the socket was created in the warning logger (if tracemalloc is enabled, see issue #26567). -- keywords: +patch Added file: http://bugs.pytho

[issue26590] socket destructor: implement finalizer

2016-03-19 Thread STINNER Victor
STINNER Victor added the comment: It's unclear to me if it's needed to call the following code in sock_dealloc(): +if (PyObject_CallFinalizerFromDealloc((PyObject *)s) < 0) +return; It looks like this code is not needed, since sock_finalize() is called before sock_dealloc(). -

[issue26590] socket destructor: implement finalizer

2016-03-18 Thread STINNER Victor
New submission from STINNER Victor: The PEP 442 helped to make object finalization safer, but it's just an API, it's not widely used in the Python core yet. io.FileIO has a nice implementation, but socket.socket and os.scandir don't. I noticed this while working on the issue #26567 which indir