Skip to content

Commit

Permalink
Close internal session when transport is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
cedk authored and mvantellingen committed Nov 11, 2021
1 parent 25701f0 commit c7d916c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/zeep/transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, cache=None, timeout=300, operation_timeout=None, session=None
self.operation_timeout = operation_timeout
self.logger = logging.getLogger(__name__)

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

def __del__(self):
if self.__close_session:
self.session.close()


class AsyncTransport(Transport):
"""Asynchronous Transport class using httpx.
Expand Down

0 comments on commit c7d916c

Please sign in to comment.