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
15+ import unittest .mock
1416try :
1517 import threading
1618except ImportError :
@@ -273,6 +275,21 @@ class TestAsynchat_WithPoll(TestAsynchat):
273275 usepoll = True
274276
275277
278+ class TestAsynchatMocked (unittest .TestCase ):
279+ def test_blockingioerror (self ):
280+ # Issue #16133: handle_read() must ignore BlockingIOError
281+ sock = unittest .mock .Mock ()
282+ sock .recv .side_effect = BlockingIOError (errno .EAGAIN )
283+
284+ dispatcher = asynchat .async_chat ()
285+ dispatcher .set_socket (sock )
286+ self .addCleanup (dispatcher .del_channel )
287+
288+ with unittest .mock .patch .object (dispatcher , 'handle_error' ) as error :
289+ dispatcher .handle_read ()
290+ self .assertFalse (error .called )
291+
292+
276293class TestHelperFunctions (unittest .TestCase ):
277294 def test_find_prefix_at_end (self ):
278295 self .assertEqual (asynchat .find_prefix_at_end ("qwerty\r " , "\r \n " ), 1 )
Original file line number Diff line number Diff line change @@ -27,6 +27,9 @@ Core and Builtins
2727Library
2828-------
2929
30+ - Issue #16133: The asynchat.async_chat.handle_read() method now ignores
31+ BlockingIOError exceptions.
32+
3033- Issue #19884: readline: Disable the meta modifier key if stdout is not
3134 a terminal to not write the ANSI sequence "\033[1034h" into stdout. This
3235 sequence is used on some terminal (ex: TERM=xterm-256color") to enable
You can’t perform that action at this time.
0 commit comments