ui.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:x112v4l2 作者: romlok 项目源码 文件源码
def start_process(self):
        """
            Start the ffmpeg subprocess
        """
        if self.process and self.process.poll() is None:
            raise RuntimeError('Refusing to start process when already running')

        cmd = self.get_process_command()
        self.process = subprocess.Popen(
            cmd,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            stdin=subprocess.DEVNULL,
        )
        # Make the pipes non-blocking
        flags = fcntl.fcntl(self.process.stdout, fcntl.F_GETFL)
        fcntl.fcntl(self.process.stdout, fcntl.F_SETFL, flags | os.O_NONBLOCK)
        flags = fcntl.fcntl(self.process.stderr, fcntl.F_GETFL)
        fcntl.fcntl(self.process.stderr, fcntl.F_SETFL, flags | os.O_NONBLOCK)
        # Clear any output from previous incarnations
        self.clear_process_stdout()
        self.clear_process_stderr()

        # Update the UI when there's output from the process
        def output_callback(fd, condition, pipe, func):
            """ Read from pipe, and pass to the given func """
            output = pipe.read()
            if not output:
                return False
            func(output.decode('utf-8'))
            return condition != GLib.IO_HUP

        stdout_read_cb = GLib.io_add_watch(
            self.process.stdout,
            GLib.PRIORITY_DEFAULT,
            GLib.IO_IN | GLib.IO_HUP,
            output_callback,
            self.process.stdout,
            self.append_process_stdout,
        )
        GLib.io_add_watch(
            self.process.stderr,
            GLib.PRIORITY_DEFAULT,
            GLib.IO_IN | GLib.IO_HUP,
            output_callback,
            self.process.stderr,
            self.append_process_stderr,
        )

        # Update the UI
        self.show_process_state()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号