aboutsummaryrefslogtreecommitdiff
blob: a0e532e278aaf6be3098f6d0ef9929baa7c87684 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Copyright 2012-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

import portage
from _emerge.SubProcess import SubProcess


class PopenProcess(SubProcess):
    __slots__ = (
        "pipe_reader",
        "proc",
    )

    def _start(self):
        self._proc = portage.process.Process(self.proc.pid)
        self._registered = True

        if self.pipe_reader is None:
            self.scheduler.call_soon(self._async_waitpid)
        else:
            try:
                self.pipe_reader.scheduler = self.scheduler
            except AttributeError:
                pass
            self.pipe_reader.addExitListener(self._pipe_reader_exit)
            self.pipe_reader.start()

    def _pipe_reader_exit(self, pipe_reader):
        self._async_waitpid()

    def _async_waitpid_cb(self, *args, **kwargs):
        SubProcess._async_waitpid_cb(self, *args, **kwargs)
        if self.proc.returncode is None:
            # Suppress warning messages like this:
            # ResourceWarning: subprocess 1234 is still running
            self.proc.returncode = self.returncode