diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-07-24 17:00:28 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-07-24 17:00:28 (GMT) |
commit | 316b16de13bef1d6e649bc12456bdae34d685d91 (patch) | |
tree | 4e53e3667b2c4a230c98abc47d2e44db49f1903a | |
parent | e1d24f7ec3d3d6011c790fdc5088ed5dde81723f (diff) | |
parent | 45cff66cf63593695ff5324d3765d8a1a1125adf (diff) | |
download | cpython-316b16de13bef1d6e649bc12456bdae34d685d91.zip cpython-316b16de13bef1d6e649bc12456bdae34d685d91.tar.gz cpython-316b16de13bef1d6e649bc12456bdae34d685d91.tar.bz2 |
(Merge 3.4) Issue #16133: The asynchat.async_chat.handle_read() method now
ignores BlockingIOError exceptions. Initial patch written by Xavier de Gaye.
Document also in asyncore documentation that recv() may raise BlockingIOError.
-rw-r--r-- | Doc/library/asyncore.rst | 4 | ||||
-rw-r--r-- | Lib/asynchat.py | 2 | ||||
-rw-r--r-- | Lib/test/test_asynchat.py | 17 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
4 files changed, 26 insertions, 0 deletions
diff --git a/Doc/library/asyncore.rst b/Doc/library/asyncore.rst index 0adf8d9..917d044 100644 --- a/Doc/library/asyncore.rst +++ b/Doc/library/asyncore.rst @@ -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) diff --git a/Lib/asynchat.py b/Lib/asynchat.py index fc6cabe..f728d1b 100644 --- a/Lib/asynchat.py +++ b/Lib/asynchat.py @@ -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 diff --git a/Lib/test/test_asynchat.py b/Lib/test/test_asynchat.py index b74b944..3a33fc8 100644 --- a/Lib/test/test_asynchat.py +++ b/Lib/test/test_asynchat.py @@ -7,11 +7,13 @@ thread = support.import_module('_thread') import asynchat import asyncore +import errno import socket import sys import time import unittest import warnings +import unittest.mock try: import threading except ImportError: @@ -274,6 +276,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) @@ -108,6 +108,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 |