commit:     be800bf0153a28ce034277d103a2021f93ac8b2e
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Apr 29 05:10:27 2018 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Apr 29 05:58:58 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=be800bf0

PopenProcess: add_child_handler asyncio compat (bug 591760)

Migrate to asyncio's AbstractChildWatcher.add_child_handler
interface.

Bug: https://bugs.gentoo.org/591760

 pym/portage/util/_async/PopenProcess.py | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/pym/portage/util/_async/PopenProcess.py 
b/pym/portage/util/_async/PopenProcess.py
index 4344b1c9d..3fb60d527 100644
--- a/pym/portage/util/_async/PopenProcess.py
+++ b/pym/portage/util/_async/PopenProcess.py
@@ -1,4 +1,4 @@
-# Copyright 2012-2017 Gentoo Foundation
+# Copyright 2012-2018 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from _emerge.SubProcess import SubProcess
@@ -13,8 +13,7 @@ class PopenProcess(SubProcess):
                self._registered = True
 
                if self.pipe_reader is None:
-                       self._reg_id = self.scheduler.child_watch_add(
-                               self.pid, self._child_watch_cb)
+                       self._async_waitpid()
                else:
                        try:
                                self.pipe_reader.scheduler = self.scheduler
@@ -24,17 +23,25 @@ class PopenProcess(SubProcess):
                        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)
+               self._async_waitpid()
 
-       def _child_watch_cb(self, pid, condition, user_data=None):
-               self._reg_id = None
-               self._waitpid_cb(pid, condition)
-               self.wait()
+       def _async_waitpid(self):
+               if self.returncode is None:
+                       self.scheduler._asyncio_child_watcher.\
+                               add_child_handler(self.pid, 
self._async_waitpid_cb)
+               else:
+                       self._unregister()
+                       self._async_wait()
 
-       def _set_returncode(self, wait_retval):
-               SubProcess._set_returncode(self, wait_retval)
+       def _async_waitpid_cb(self, pid, returncode):
                if self.proc.returncode is None:
                        # Suppress warning messages like this:
                        # ResourceWarning: subprocess 1234 is still running
-                       self.proc.returncode = self.returncode
+                       self.proc.returncode = returncode
+               self._unregister()
+               self.returncode = returncode
+               self._async_wait()
+
+       def _poll(self):
+               # Simply rely on _async_waitpid_cb to set the returncode.
+               return self.returncode

Reply via email to