Skip to content

Commit a7af841

Browse files
iritkatrielseehwan80
authored andcommitted
pythongh-131233: remove return-in-finally in multiprocessing/connection.py (python#131416)
1 parent c6b57ee commit a7af841

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

Lib/multiprocessing/connection.py

+24-14
Original file line numberDiff line numberDiff line change
@@ -322,22 +322,32 @@ def _recv_bytes(self, maxsize=None):
322322
try:
323323
ov, err = _winapi.ReadFile(self._handle, bsize,
324324
overlapped=True)
325+
326+
sentinel = object()
327+
return_value = sentinel
325328
try:
326-
if err == _winapi.ERROR_IO_PENDING:
327-
waitres = _winapi.WaitForMultipleObjects(
328-
[ov.event], False, INFINITE)
329-
assert waitres == WAIT_OBJECT_0
329+
try:
330+
if err == _winapi.ERROR_IO_PENDING:
331+
waitres = _winapi.WaitForMultipleObjects(
332+
[ov.event], False, INFINITE)
333+
assert waitres == WAIT_OBJECT_0
334+
except:
335+
ov.cancel()
336+
raise
337+
finally:
338+
nread, err = ov.GetOverlappedResult(True)
339+
if err == 0:
340+
f = io.BytesIO()
341+
f.write(ov.getbuffer())
342+
return_value = f
343+
elif err == _winapi.ERROR_MORE_DATA:
344+
return_value = self._get_more_data(ov, maxsize)
330345
except:
331-
ov.cancel()
332-
raise
333-
finally:
334-
nread, err = ov.GetOverlappedResult(True)
335-
if err == 0:
336-
f = io.BytesIO()
337-
f.write(ov.getbuffer())
338-
return f
339-
elif err == _winapi.ERROR_MORE_DATA:
340-
return self._get_more_data(ov, maxsize)
346+
if return_value is sentinel:
347+
raise
348+
349+
if return_value is not sentinel:
350+
return return_value
341351
except OSError as e:
342352
if e.winerror == _winapi.ERROR_BROKEN_PIPE:
343353
raise EOFError

0 commit comments

Comments
 (0)