Skip to content

Commit

Permalink
Always close pycurl instance
Browse files Browse the repository at this point in the history
The class has a `__del__` method, but that's not always guaranteed to
run in a timely fashion.
  • Loading branch information
mvdbeek committed Jun 13, 2024
1 parent 12f1349 commit 5e10f51
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pulsar/client/transport/curl.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def execute(self, url, method=None, data=None, input_path=None, output_path=None
if not output_path:
return buf.getvalue()
finally:
c.close()
buf.close()


Expand All @@ -69,13 +70,16 @@ def post_file(url, path):
# wrap it in a better one.
message = NO_SUCH_FILE_MESSAGE % (path, url)
raise Exception(message)
c = _new_curl_object_for_url(url)
c.setopt(c.HTTPPOST, [("file", (c.FORM_FILE, path.encode('ascii')))])
c.perform()
status_code = c.getinfo(HTTP_CODE)
if int(status_code) != 200:
message = POST_FAILED_MESSAGE % (url, status_code)
raise Exception(message)
try:
c = _new_curl_object_for_url(url)
c.setopt(c.HTTPPOST, [("file", (c.FORM_FILE, path.encode('ascii')))])
c.perform()
status_code = c.getinfo(HTTP_CODE)
if int(status_code) != 200:
message = POST_FAILED_MESSAGE % (url, status_code)
raise Exception(message)
finally:
c.close()


def get_size(url) -> int:
Expand Down Expand Up @@ -122,6 +126,7 @@ def get_file(url, path: str):
message = GET_FAILED_MESSAGE % (url, status_code)
raise Exception(message)
finally:
c.close()
buf.close()


Expand Down

0 comments on commit 5e10f51

Please sign in to comment.