]> granicus.if.org Git - python/commitdiff
Issue #16133: The asynchat.async_chat.handle_read() method now ignores
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 24 Jul 2014 16:49:36 +0000 (18:49 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 24 Jul 2014 16:49:36 +0000 (18:49 +0200)
BlockingIOError exceptions. Initial patch written by Xavier de Gaye.

Document also in asyncore documentation that recv() may raise BlockingIOError.

Doc/library/asyncore.rst
Lib/asynchat.py
Lib/test/test_asynchat.py
Misc/NEWS

index 0adf8d9c25b9c97a963db7b0bc5ef90dc2f3d7af..917d0448c2f0f7a232e770378d8b25afd7111ab7 100644 (file)
@@ -216,6 +216,10 @@ any that have been added to the map during asynchronous service) is closed.
       empty bytes object implies that the channel has been closed from the
       other end.
 
+      Note that :meth:`recv` may raise :exc:`BlockingIOError` , even though
+      :func:`select.select` or :func:`select.poll` has reported the socket
+      ready for reading.
+
 
    .. method:: listen(backlog)
 
index 6e16891d439620f6e812db1058a66f9e0b2d95cd..14c152f059b714563361ff63a869f13aeb8500a9 100644 (file)
@@ -115,6 +115,8 @@ class async_chat(asyncore.dispatcher):
 
         try:
             data = self.recv(self.ac_in_buffer_size)
+        except BlockingIOError:
+            return
         except OSError as why:
             self.handle_error()
             return
index 84867ec8206d038f25b240bc7ade6d5a03d948da..2dc9d0c17a3ea4de6bede064d339b26b219f5738 100644 (file)
@@ -7,10 +7,12 @@ thread = support.import_module('_thread')
 
 import asynchat
 import asyncore
+import errno
 import socket
 import sys
 import time
 import unittest
+import unittest.mock
 try:
     import threading
 except ImportError:
@@ -273,6 +275,21 @@ class TestAsynchat_WithPoll(TestAsynchat):
     usepoll = True
 
 
+class TestAsynchatMocked(unittest.TestCase):
+    def test_blockingioerror(self):
+        # Issue #16133: handle_read() must ignore BlockingIOError
+        sock = unittest.mock.Mock()
+        sock.recv.side_effect = BlockingIOError(errno.EAGAIN)
+
+        dispatcher = asynchat.async_chat()
+        dispatcher.set_socket(sock)
+        self.addCleanup(dispatcher.del_channel)
+
+        with unittest.mock.patch.object(dispatcher, 'handle_error') as error:
+            dispatcher.handle_read()
+        self.assertFalse(error.called)
+
+
 class TestHelperFunctions(unittest.TestCase):
     def test_find_prefix_at_end(self):
         self.assertEqual(asynchat.find_prefix_at_end("qwerty\r", "\r\n"), 1)
index 0def1949a77f31831e5909564e9c45dfcea44626..4fb4b3f6403f8bd9588961d75cfd54d84fbae728 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #16133: The asynchat.async_chat.handle_read() method now ignores
+  BlockingIOError exceptions.
+
 - Issue #19884: readline: Disable the meta modifier key if stdout is not
   a terminal to not write the ANSI sequence "\033[1034h" into stdout. This
   sequence is used on some terminal (ex: TERM=xterm-256color") to enable