Merge pull request #630 from evandroforks/close_http_client_connections
Fixed HttpClient session not being closed
This commit is contained in:
commit
8300d8d85c
@ -28,6 +28,20 @@ class HttpClient:
|
||||
self.progress_hook = progress_hook
|
||||
self.session = requests.Session()
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
self.close()
|
||||
|
||||
def close(self):
|
||||
if self.session:
|
||||
self.session.close()
|
||||
self.session = None
|
||||
|
||||
def __del__(self):
|
||||
self.close()
|
||||
|
||||
def post(self, url: str, data: Any, headers: Optional[Dict[str, str]]) -> Response:
|
||||
data = _MonitoringFile(
|
||||
data, hook=self.progress_hook
|
||||
|
@ -803,6 +803,7 @@ to a cloze type first, via Edit>Change Note Type."""
|
||||
local = False
|
||||
# fetch it into a temporary folder
|
||||
self.mw.progress.start(immediate=not local, parent=self.parentWindow)
|
||||
r = None
|
||||
ct = None
|
||||
error_msg: Optional[str] = None
|
||||
try:
|
||||
@ -825,6 +826,8 @@ to a cloze type first, via Edit>Change Note Type."""
|
||||
error_msg = _("An error occurred while opening %s") % e
|
||||
return
|
||||
finally:
|
||||
if r:
|
||||
r.close()
|
||||
self.mw.progress.finish()
|
||||
if error_msg:
|
||||
showWarning(error_msg)
|
||||
|
Loading…
Reference in New Issue
Block a user