Skip to content

Commit 5e10f51

Browse files
committed
Always close pycurl instance
The class has a `__del__` method, but that's not always guaranteed to run in a timely fashion.
1 parent 12f1349 commit 5e10f51

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

pulsar/client/transport/curl.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def execute(self, url, method=None, data=None, input_path=None, output_path=None
6060
if not output_path:
6161
return buf.getvalue()
6262
finally:
63+
c.close()
6364
buf.close()
6465

6566

@@ -69,13 +70,16 @@ def post_file(url, path):
6970
# wrap it in a better one.
7071
message = NO_SUCH_FILE_MESSAGE % (path, url)
7172
raise Exception(message)
72-
c = _new_curl_object_for_url(url)
73-
c.setopt(c.HTTPPOST, [("file", (c.FORM_FILE, path.encode('ascii')))])
74-
c.perform()
75-
status_code = c.getinfo(HTTP_CODE)
76-
if int(status_code) != 200:
77-
message = POST_FAILED_MESSAGE % (url, status_code)
78-
raise Exception(message)
73+
try:
74+
c = _new_curl_object_for_url(url)
75+
c.setopt(c.HTTPPOST, [("file", (c.FORM_FILE, path.encode('ascii')))])
76+
c.perform()
77+
status_code = c.getinfo(HTTP_CODE)
78+
if int(status_code) != 200:
79+
message = POST_FAILED_MESSAGE % (url, status_code)
80+
raise Exception(message)
81+
finally:
82+
c.close()
7983

8084

8185
def get_size(url) -> int:
@@ -122,6 +126,7 @@ def get_file(url, path: str):
122126
message = GET_FAILED_MESSAGE % (url, status_code)
123127
raise Exception(message)
124128
finally:
129+
c.close()
125130
buf.close()
126131

127132

0 commit comments

Comments
 (0)