From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id B94541382C5 for ; Mon, 30 Apr 2018 06:29:30 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E9A9FE0BF2; Mon, 30 Apr 2018 06:29:29 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id AF1EFE0BF2 for ; Mon, 30 Apr 2018 06:29:29 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 17F89335C9C for ; Mon, 30 Apr 2018 06:29:28 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 470932A4 for ; Mon, 30 Apr 2018 06:29:26 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1525069201.c06c7e50244292e263e5512f7baefc16bbe85456.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/_emerge/ X-VCS-Repository: proj/portage X-VCS-Files: pym/_emerge/EbuildIpcDaemon.py pym/_emerge/FifoIpcDaemon.py X-VCS-Directories: pym/_emerge/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: c06c7e50244292e263e5512f7baefc16bbe85456 X-VCS-Branch: master Date: Mon, 30 Apr 2018 06:29:26 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 59b07677-1654-4d87-9071-3992d0bc30ef X-Archives-Hash: 5d44aaf1662e38fbb9cba802702bdbfc commit: c06c7e50244292e263e5512f7baefc16bbe85456 Author: Zac Medico gentoo org> AuthorDate: Mon Apr 30 04:05:22 2018 +0000 Commit: Zac Medico gentoo org> CommitDate: Mon Apr 30 06:20:01 2018 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=c06c7e50 EbuildIpcDaemon: add_reader asyncio compat (bug 654382) Use add_reader for asyncio compatibility. Bug: https://bugs.gentoo.org/654382 pym/_emerge/EbuildIpcDaemon.py | 28 +++++++--------------------- pym/_emerge/FifoIpcDaemon.py | 20 ++++++++------------ 2 files changed, 15 insertions(+), 33 deletions(-) diff --git a/pym/_emerge/EbuildIpcDaemon.py b/pym/_emerge/EbuildIpcDaemon.py index 8414d2020..c16049ee4 100644 --- a/pym/_emerge/EbuildIpcDaemon.py +++ b/pym/_emerge/EbuildIpcDaemon.py @@ -1,4 +1,4 @@ -# Copyright 2010-2012 Gentoo Foundation +# Copyright 2010-2018 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import errno @@ -32,24 +32,12 @@ class EbuildIpcDaemon(FifoIpcDaemon): __slots__ = ('commands',) - def _input_handler(self, fd, event): + def _input_handler(self): # Read the whole pickle in a single atomic read() call. - data = None - if event & self.scheduler.IO_IN: - # For maximum portability, use os.read() here since - # array.fromfile() and file.read() are both known to - # erroneously return an empty string from this - # non-blocking fifo stream on FreeBSD (bug #337465). - try: - data = os.read(fd, self._bufsize) - except OSError as e: - if e.errno != errno.EAGAIN: - raise - # Assume that another event will be generated - # if there's any relevant data. - - if data: - + data = self._read_buf(self._files.pipe_in, None) + if data is None: + pass # EAGAIN + elif data: try: obj = pickle.loads(data) except SystemExit: @@ -85,7 +73,7 @@ class EbuildIpcDaemon(FifoIpcDaemon): if reply_hook is not None: reply_hook() - elif event & self.scheduler.IO_HUP: + else: # EIO/POLLHUP # This can be triggered due to a race condition which happens when # the previous _reopen_input() call occurs before the writer has # closed the pipe (see bug #401919). It's not safe to re-open @@ -107,8 +95,6 @@ class EbuildIpcDaemon(FifoIpcDaemon): finally: unlockfile(lock_obj) - return True - def _send_reply(self, reply): # File streams are in unbuffered mode since we do atomic # read and write of whole pickles. Use non-blocking mode so diff --git a/pym/_emerge/FifoIpcDaemon.py b/pym/_emerge/FifoIpcDaemon.py index 3676e98da..0cbaa13c7 100644 --- a/pym/_emerge/FifoIpcDaemon.py +++ b/pym/_emerge/FifoIpcDaemon.py @@ -15,8 +15,7 @@ from portage.cache.mappings import slot_dict_class class FifoIpcDaemon(AbstractPollTask): - __slots__ = ("input_fifo", "output_fifo",) + \ - ("_files", "_reg_id",) + __slots__ = ("input_fifo", "output_fifo", "_files") _file_names = ("pipe_in",) _files_dict = slot_dict_class(_file_names, prefix="") @@ -40,9 +39,9 @@ class FifoIpcDaemon(AbstractPollTask): fcntl.fcntl(self._files.pipe_in, fcntl.F_GETFD) | fcntl.FD_CLOEXEC) - self._reg_id = self.scheduler.io_add_watch( + self.scheduler.add_reader( self._files.pipe_in, - self._registered_events, self._input_handler) + self._input_handler) self._registered = True @@ -51,7 +50,7 @@ class FifoIpcDaemon(AbstractPollTask): Re-open the input stream, in order to suppress POLLHUP events (bug #339976). """ - self.scheduler.source_remove(self._reg_id) + self.scheduler.remove_reader(self._files.pipe_in) os.close(self._files.pipe_in) self._files.pipe_in = \ os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK) @@ -67,9 +66,9 @@ class FifoIpcDaemon(AbstractPollTask): fcntl.fcntl(self._files.pipe_in, fcntl.F_GETFD) | fcntl.FD_CLOEXEC) - self._reg_id = self.scheduler.io_add_watch( + self.scheduler.add_reader( self._files.pipe_in, - self._registered_events, self._input_handler) + self._input_handler) def isAlive(self): return self._registered @@ -81,7 +80,7 @@ class FifoIpcDaemon(AbstractPollTask): # notify exit listeners self._async_wait() - def _input_handler(self, fd, event): + def _input_handler(self): raise NotImplementedError(self) def _unregister(self): @@ -91,11 +90,8 @@ class FifoIpcDaemon(AbstractPollTask): self._registered = False - if self._reg_id is not None: - self.scheduler.source_remove(self._reg_id) - self._reg_id = None - if self._files is not None: for f in self._files.values(): + self.scheduler.remove_reader(f) os.close(f) self._files = None