From a13c6739cab86f196fbc8a220f0d238c3544bae9 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 16 Oct 2012 10:31:34 -0700 Subject: [PATCH] PopenProcess: integrate PipeReader support --- .../ebuild/_parallel_manifest/ManifestTask.py | 23 +++++++------------ pym/portage/util/_async/PopenProcess.py | 16 +++++++++++-- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/pym/portage/package/ebuild/_parallel_manifest/ManifestTask.py b/pym/portage/package/ebuild/_parallel_manifest/ManifestTask.py index fbb3c8856..83ef89094 100644 --- a/pym/portage/package/ebuild/_parallel_manifest/ManifestTask.py +++ b/pym/portage/package/ebuild/_parallel_manifest/ManifestTask.py @@ -38,11 +38,6 @@ class ManifestTask(CompositeTask): self._proc.cancel() CompositeTask._cancel(self) - def _proc_wait(self): - if self._proc is not None: - self._proc.wait() - self._proc = None - def _manifest_proc_exit(self, manifest_proc): self._assert_current(manifest_proc) if manifest_proc.returncode not in (os.EX_OK, manifest_proc.MODIFIED): @@ -73,11 +68,11 @@ class ManifestTask(CompositeTask): self._proc = PopenProcess(proc=subprocess.Popen( ["gpg", "--verify", self._manifest_path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT), + pipe_reader=PipeReader(scheduler=self.scheduler), scheduler=self.scheduler) - pipe_reader = PipeReader( - input_files={"producer" : self._proc.proc.stdout}, - scheduler=self.scheduler) - self._start_task(pipe_reader, self._check_sig_key_exit) + self._proc.pipe_reader.input_files = { + "producer" : self._proc.proc.stdout} + self._start_task(self._proc, self._check_sig_key_exit) @staticmethod def _parse_gpg_key(output): @@ -92,16 +87,16 @@ class ManifestTask(CompositeTask): return output[-1] return None - def _check_sig_key_exit(self, pipe_reader): - self._assert_current(pipe_reader) + def _check_sig_key_exit(self, proc): + self._assert_current(proc) + self._proc = None parsed_key = self._parse_gpg_key( - pipe_reader.getvalue().decode('utf_8', 'replace')) + proc.pipe_reader.getvalue().decode('utf_8', 'replace')) if parsed_key is not None and \ parsed_key.lower() in self.force_sign_key.lower(): self.returncode = os.EX_OK self._current_task = None - self._proc_wait() self.wait() return @@ -142,7 +137,6 @@ class ManifestTask(CompositeTask): def _gpg_proc_exit(self, gpg_proc): if self._default_exit(gpg_proc) != os.EX_OK: - self._proc_wait() self.wait() return @@ -161,7 +155,6 @@ class ManifestTask(CompositeTask): self.returncode = os.EX_OK self._current_task = None - self._proc_wait() self.wait() def _need_signature(self): diff --git a/pym/portage/util/_async/PopenProcess.py b/pym/portage/util/_async/PopenProcess.py index 7c42c85b3..c3ae6e9db 100644 --- a/pym/portage/util/_async/PopenProcess.py +++ b/pym/portage/util/_async/PopenProcess.py @@ -5,11 +5,23 @@ from _emerge.SubProcess import SubProcess class PopenProcess(SubProcess): - __slots__ = ("proc",) + __slots__ = ("pipe_reader", "proc",) def __init__(self, **kwargs): SubProcess.__init__(self, **kwargs) self.pid = self.proc.pid + self._registered = True def _start(self): - pass + if self.pipe_reader is not None: + self.pipe_reader.addExitListener(self._pipe_reader_exit) + self.pipe_reader.start() + + def _pipe_reader_exit(self, pipe_reader): + self._reg_id = self.scheduler.child_watch_add( + self.pid, self._child_watch_cb) + + def _child_watch_cb(self, pid, condition, user_data=None): + self._reg_id = None + self._waitpid_cb(pid, condition) + self.wait() -- 2.26.2