diff options
author | Guido van Rossum <guido@python.org> | 2014-05-06 21:45:39 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2014-05-06 21:45:39 (GMT) |
commit | 5dcad2c8f3fe5055fc808d79bde005d0b741fb24 (patch) | |
tree | b25b8d4eb031f27ab97f942670c8f3161e419d72 /Lib/asyncio/selector_events.py | |
parent | bca9694ac1cc41f091fb78badbc1d1673b35077a (diff) | |
parent | 3d139d8ed6712f39f4e91dc084ed421b76af09ae (diff) | |
download | cpython-5dcad2c8f3fe5055fc808d79bde005d0b741fb24.zip cpython-5dcad2c8f3fe5055fc808d79bde005d0b741fb24.tar.gz cpython-5dcad2c8f3fe5055fc808d79bde005d0b741fb24.tar.bz2 |
Merge 3.4->default: asyncio: Fix the second half of issue #21447: race in _write_to_self().
Diffstat (limited to 'Lib/asyncio/selector_events.py')
-rw-r--r-- | Lib/asyncio/selector_events.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index 367c5fb..c7df8d8 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -87,10 +87,17 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): pass def _write_to_self(self): - try: - self._csock.send(b'x') - except (BlockingIOError, InterruptedError): - pass + # This may be called from a different thread, possibly after + # _close_self_pipe() has been called or even while it is + # running. Guard for self._csock being None or closed. When + # a socket is closed, send() raises OSError (with errno set to + # EBADF, but let's not rely on the exact error code). + csock = self._csock + if csock is not None: + try: + csock.send(b'x') + except OSError: + pass def _start_serving(self, protocol_factory, sock, sslcontext=None, server=None): |