Skip to content

Commit 715180a

Browse files
mvdbeeknuwang
andauthored
Use context manager
Co-authored-by: Nuwan Goonasekera <[email protected]>
1 parent 5e10f51 commit 715180a

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

pulsar/client/transport/curl.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,13 @@ def post_file(url, path):
7070
# wrap it in a better one.
7171
message = NO_SUCH_FILE_MESSAGE % (path, url)
7272
raise Exception(message)
73-
try:
74-
c = _new_curl_object_for_url(url)
73+
with contextlib.closing(_new_curl_object_for_url(url)) as c:
7574
c.setopt(c.HTTPPOST, [("file", (c.FORM_FILE, path.encode('ascii')))])
7675
c.perform()
7776
status_code = c.getinfo(HTTP_CODE)
7877
if int(status_code) != 200:
7978
message = POST_FAILED_MESSAGE % (url, status_code)
8079
raise Exception(message)
81-
finally:
82-
c.close()
8380

8481

8582
def get_size(url) -> int:

0 commit comments

Comments
 (0)