Skip to content

Commit c7d916c

Browse files
cedkmvantellingen
authored andcommitted
Close internal session when transport is deleted
1 parent 25701f0 commit c7d916c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/zeep/transports.py

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self, cache=None, timeout=300, operation_timeout=None, session=None
3737
self.operation_timeout = operation_timeout
3838
self.logger = logging.getLogger(__name__)
3939

40+
self.__close_session = not session
4041
self.session = session or requests.Session()
4142
self.session.mount("file://", FileAdapter())
4243
self.session.headers["User-Agent"] = "Zeep/%s (www.python-zeep.org)" % (
@@ -154,6 +155,10 @@ def settings(self, timeout=None):
154155
yield
155156
self.operation_timeout = old_timeout
156157

158+
def __del__(self):
159+
if self.__close_session:
160+
self.session.close()
161+
157162

158163
class AsyncTransport(Transport):
159164
"""Asynchronous Transport class using httpx.

0 commit comments

Comments
 (0)