File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -216,6 +216,10 @@ any that have been added to the map during asynchronous service) is closed.
216216 empty bytes object implies that the channel has been closed from the
217217 other end.
218218
219+ Note that :meth: `recv ` may raise :exc: `BlockingIOError ` , even though
220+ :func: `select.select ` or :func: `select.poll ` has reported the socket
221+ ready for reading.
222+
219223
220224 .. method :: listen(backlog)
221225
Original file line number Diff line number Diff line change @@ -115,6 +115,8 @@ def handle_read(self):
115115
116116 try :
117117 data = self .recv (self .ac_in_buffer_size )
118+ except BlockingIOError :
119+ return
118120 except OSError as why :
119121 self .handle_error ()
120122 return
Original file line number Diff line number Diff line change 77
88import asynchat
99import asyncore
10+ import errno
1011import socket
1112import sys
1213import time
1314import unittest
1415import warnings
16+ import unittest .mock
1517try :
1618 import threading
1719except ImportError :
@@ -274,6 +276,21 @@ class TestAsynchat_WithPoll(TestAsynchat):
274276 usepoll = True
275277
276278
279+ class TestAsynchatMocked (unittest .TestCase ):
280+ def test_blockingioerror (self ):
281+ # Issue #16133: handle_read() must ignore BlockingIOError
282+ sock = unittest .mock .Mock ()
283+ sock .recv .side_effect = BlockingIOError (errno .EAGAIN )
284+
285+ dispatcher = asynchat .async_chat ()
286+ dispatcher .set_socket (sock )
287+ self .addCleanup (dispatcher .del_channel )
288+
289+ with unittest .mock .patch .object (dispatcher , 'handle_error' ) as error :
290+ dispatcher .handle_read ()
291+ self .assertFalse (error .called )
292+
293+
277294class TestHelperFunctions (unittest .TestCase ):
278295 def test_find_prefix_at_end (self ):
279296 self .assertEqual (asynchat .find_prefix_at_end ("qwerty\r " , "\r \n " ), 1 )
Original file line number Diff line number Diff line change @@ -108,6 +108,9 @@ Core and Builtins
108108Library
109109-------
110110
111+ - Issue #16133: The asynchat.async_chat.handle_read() method now ignores
112+ BlockingIOError exceptions.
113+
111114- Issue #19884: readline: Disable the meta modifier key if stdout is not
112115 a terminal to not write the ANSI sequence "\033[1034h" into stdout. This
113116 sequence is used on some terminal (ex: TERM=xterm-256color") to enable
You can’t perform that action at this time.
0 commit comments