From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Fri, 21 Mar 2025 18:05:47 +0000 (+0000) Subject: gh-131233: remove return-in-finally in multiprocessing/connection.py (#131416) X-Git-Tag: v3.14.0a7~256 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3e2cceaa871a742a66711519d8e6998b186ae263;p=thirdparty%2FPython%2Fcpython.git gh-131233: remove return-in-finally in multiprocessing/connection.py (#131416) --- diff --git a/Lib/multiprocessing/connection.py b/Lib/multiprocessing/connection.py index d429212d4473..5f288a8d3932 100644 --- a/Lib/multiprocessing/connection.py +++ b/Lib/multiprocessing/connection.py @@ -322,22 +322,32 @@ if _winapi: try: ov, err = _winapi.ReadFile(self._handle, bsize, overlapped=True) + + sentinel = object() + return_value = sentinel try: - if err == _winapi.ERROR_IO_PENDING: - waitres = _winapi.WaitForMultipleObjects( - [ov.event], False, INFINITE) - assert waitres == WAIT_OBJECT_0 + try: + if err == _winapi.ERROR_IO_PENDING: + waitres = _winapi.WaitForMultipleObjects( + [ov.event], False, INFINITE) + assert waitres == WAIT_OBJECT_0 + except: + ov.cancel() + raise + finally: + nread, err = ov.GetOverlappedResult(True) + if err == 0: + f = io.BytesIO() + f.write(ov.getbuffer()) + return_value = f + elif err == _winapi.ERROR_MORE_DATA: + return_value = self._get_more_data(ov, maxsize) except: - ov.cancel() - raise - finally: - nread, err = ov.GetOverlappedResult(True) - if err == 0: - f = io.BytesIO() - f.write(ov.getbuffer()) - return f - elif err == _winapi.ERROR_MORE_DATA: - return self._get_more_data(ov, maxsize) + if return_value is sentinel: + raise + + if return_value is not sentinel: + return return_value except OSError as e: if e.winerror == _winapi.ERROR_BROKEN_PIPE: raise EOFError