Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: pym/_emerge/
Date: Mon, 30 Apr 2018 06:29:30
Message-Id: 1525069201.c06c7e50244292e263e5512f7baefc16bbe85456.zmedico@gentoo
1 commit: c06c7e50244292e263e5512f7baefc16bbe85456
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Mon Apr 30 04:05:22 2018 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Mon Apr 30 06:20:01 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=c06c7e50
7
8 EbuildIpcDaemon: add_reader asyncio compat (bug 654382)
9
10 Use add_reader for asyncio compatibility.
11
12 Bug: https://bugs.gentoo.org/654382
13
14 pym/_emerge/EbuildIpcDaemon.py | 28 +++++++---------------------
15 pym/_emerge/FifoIpcDaemon.py | 20 ++++++++------------
16 2 files changed, 15 insertions(+), 33 deletions(-)
17
18 diff --git a/pym/_emerge/EbuildIpcDaemon.py b/pym/_emerge/EbuildIpcDaemon.py
19 index 8414d2020..c16049ee4 100644
20 --- a/pym/_emerge/EbuildIpcDaemon.py
21 +++ b/pym/_emerge/EbuildIpcDaemon.py
22 @@ -1,4 +1,4 @@
23 -# Copyright 2010-2012 Gentoo Foundation
24 +# Copyright 2010-2018 Gentoo Foundation
25 # Distributed under the terms of the GNU General Public License v2
26
27 import errno
28 @@ -32,24 +32,12 @@ class EbuildIpcDaemon(FifoIpcDaemon):
29
30 __slots__ = ('commands',)
31
32 - def _input_handler(self, fd, event):
33 + def _input_handler(self):
34 # Read the whole pickle in a single atomic read() call.
35 - data = None
36 - if event & self.scheduler.IO_IN:
37 - # For maximum portability, use os.read() here since
38 - # array.fromfile() and file.read() are both known to
39 - # erroneously return an empty string from this
40 - # non-blocking fifo stream on FreeBSD (bug #337465).
41 - try:
42 - data = os.read(fd, self._bufsize)
43 - except OSError as e:
44 - if e.errno != errno.EAGAIN:
45 - raise
46 - # Assume that another event will be generated
47 - # if there's any relevant data.
48 -
49 - if data:
50 -
51 + data = self._read_buf(self._files.pipe_in, None)
52 + if data is None:
53 + pass # EAGAIN
54 + elif data:
55 try:
56 obj = pickle.loads(data)
57 except SystemExit:
58 @@ -85,7 +73,7 @@ class EbuildIpcDaemon(FifoIpcDaemon):
59 if reply_hook is not None:
60 reply_hook()
61
62 - elif event & self.scheduler.IO_HUP:
63 + else: # EIO/POLLHUP
64 # This can be triggered due to a race condition which happens when
65 # the previous _reopen_input() call occurs before the writer has
66 # closed the pipe (see bug #401919). It's not safe to re-open
67 @@ -107,8 +95,6 @@ class EbuildIpcDaemon(FifoIpcDaemon):
68 finally:
69 unlockfile(lock_obj)
70
71 - return True
72 -
73 def _send_reply(self, reply):
74 # File streams are in unbuffered mode since we do atomic
75 # read and write of whole pickles. Use non-blocking mode so
76
77 diff --git a/pym/_emerge/FifoIpcDaemon.py b/pym/_emerge/FifoIpcDaemon.py
78 index 3676e98da..0cbaa13c7 100644
79 --- a/pym/_emerge/FifoIpcDaemon.py
80 +++ b/pym/_emerge/FifoIpcDaemon.py
81 @@ -15,8 +15,7 @@ from portage.cache.mappings import slot_dict_class
82
83 class FifoIpcDaemon(AbstractPollTask):
84
85 - __slots__ = ("input_fifo", "output_fifo",) + \
86 - ("_files", "_reg_id",)
87 + __slots__ = ("input_fifo", "output_fifo", "_files")
88
89 _file_names = ("pipe_in",)
90 _files_dict = slot_dict_class(_file_names, prefix="")
91 @@ -40,9 +39,9 @@ class FifoIpcDaemon(AbstractPollTask):
92 fcntl.fcntl(self._files.pipe_in,
93 fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
94
95 - self._reg_id = self.scheduler.io_add_watch(
96 + self.scheduler.add_reader(
97 self._files.pipe_in,
98 - self._registered_events, self._input_handler)
99 + self._input_handler)
100
101 self._registered = True
102
103 @@ -51,7 +50,7 @@ class FifoIpcDaemon(AbstractPollTask):
104 Re-open the input stream, in order to suppress
105 POLLHUP events (bug #339976).
106 """
107 - self.scheduler.source_remove(self._reg_id)
108 + self.scheduler.remove_reader(self._files.pipe_in)
109 os.close(self._files.pipe_in)
110 self._files.pipe_in = \
111 os.open(self.input_fifo, os.O_RDONLY|os.O_NONBLOCK)
112 @@ -67,9 +66,9 @@ class FifoIpcDaemon(AbstractPollTask):
113 fcntl.fcntl(self._files.pipe_in,
114 fcntl.F_GETFD) | fcntl.FD_CLOEXEC)
115
116 - self._reg_id = self.scheduler.io_add_watch(
117 + self.scheduler.add_reader(
118 self._files.pipe_in,
119 - self._registered_events, self._input_handler)
120 + self._input_handler)
121
122 def isAlive(self):
123 return self._registered
124 @@ -81,7 +80,7 @@ class FifoIpcDaemon(AbstractPollTask):
125 # notify exit listeners
126 self._async_wait()
127
128 - def _input_handler(self, fd, event):
129 + def _input_handler(self):
130 raise NotImplementedError(self)
131
132 def _unregister(self):
133 @@ -91,11 +90,8 @@ class FifoIpcDaemon(AbstractPollTask):
134
135 self._registered = False
136
137 - if self._reg_id is not None:
138 - self.scheduler.source_remove(self._reg_id)
139 - self._reg_id = None
140 -
141 if self._files is not None:
142 for f in self._files.values():
143 + self.scheduler.remove_reader(f)
144 os.close(f)
145 self._files = None