summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Agronick <agronick@gmail.com>2017-05-04 10:06:07 -0400
committerPierce Lopez <pierce.lopez@gmail.com>2017-06-06 17:03:22 -0400
commit81e28fb2fa4bfeff96b69b32620739cc2e9aa45d (patch)
treec0aed468b6eca17a28c5efebdd70d9a322ffb29d
parentbcf960f645169c0e7cb6eed57b73f01789059bdf (diff)
downloadparamiko-81e28fb2fa4bfeff96b69b32620739cc2e9aa45d.tar.gz
remove ResourceManager to fix leak of Transport/SSHClient
The back-reference from Transport to SSHClient was added because the SSHClient had a destructor that would close the Transport, and some users did not want the Transport closed when the SSHClient was garbage collected. The SSHClient destructor was not a normal destructor, it was implemented with the ResourceManager singleton. Together with the back-reference, this prevented the GC cycle detector from freeing the SSHClient and Transport.
-rw-r--r--paramiko/client.py2
-rw-r--r--paramiko/resource.py71
2 files changed, 0 insertions, 73 deletions
diff --git a/paramiko/client.py b/paramiko/client.py
index 18139416..0c2941e5 100644
--- a/paramiko/client.py
+++ b/paramiko/client.py
@@ -34,7 +34,6 @@ from paramiko.dsskey import DSSKey
from paramiko.ecdsakey import ECDSAKey
from paramiko.hostkeys import HostKeys
from paramiko.py3compat import string_types
-from paramiko.resource import ResourceManager
from paramiko.rsakey import RSAKey
from paramiko.ssh_exception import (
SSHException, BadHostKeyException, NoValidConnectionsError
@@ -337,7 +336,6 @@ class SSHClient (ClosingContextManager):
t.banner_timeout = banner_timeout
t.start_client()
t.set_sshclient(self)
- ResourceManager.register(self, t)
server_key = t.get_remote_server_key()
keytype = server_key.get_name()
diff --git a/paramiko/resource.py b/paramiko/resource.py
deleted file mode 100644
index 9809afbe..00000000
--- a/paramiko/resource.py
+++ /dev/null
@@ -1,71 +0,0 @@
-# Copyright (C) 2003-2007 Robey Pointer <robeypointer@gmail.com>
-#
-# This file is part of paramiko.
-#
-# Paramiko is free software; you can redistribute it and/or modify it under the
-# terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation; either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# Paramiko is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
-# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-
-"""
-Resource manager.
-"""
-
-import weakref
-
-
-class ResourceManager (object):
- """
- A registry of objects and resources that should be closed when those
- objects are deleted.
-
- This is meant to be a safer alternative to Python's ``__del__`` method,
- which can cause reference cycles to never be collected. Objects registered
- with the ResourceManager can be collected but still free resources when
- they die.
-
- Resources are registered using `register`, and when an object is garbage
- collected, each registered resource is closed by having its ``close()``
- method called. Multiple resources may be registered per object, but a
- resource will only be closed once, even if multiple objects register it.
- (The last object to register it wins.)
- """
-
- def __init__(self):
- self._table = {}
-
- def register(self, obj, resource):
- """
- Register a resource to be closed with an object is collected.
-
- When the given ``obj`` is garbage-collected by the Python interpreter,
- the ``resource`` will be closed by having its ``close()`` method called.
- Any exceptions are ignored.
-
- :param object obj: the object to track
- :param object resource:
- the resource to close when the object is collected
- """
- def callback(ref):
- try:
- resource.close()
- except:
- pass
- del self._table[id(resource)]
-
- # keep the weakref in a table so it sticks around long enough to get
- # its callback called. :)
- self._table[id(resource)] = weakref.ref(obj, callback)
-
-
-# singleton
-ResourceManager = ResourceManager()