def cmd_async(self, cmd, cwd=None, **callbacks):
        command = self.build_command(cmd)
        environment = self.env()
        encoding = get_setting('encoding', 'utf-8')
        fallback = get_setting('fallback_encodings', [])

        def async_inner(cmd, cwd, encoding, on_data=None, on_complete=None, on_error=None, on_exception=None):
            try:
                logger.debug('async-cmd: %s', cmd)

                if cwd:
                    os.chdir(cwd)

                proc = subprocess.Popen(cmd,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.STDOUT,
                                        startupinfo=self.startupinfo(),
                                        env=environment)

                for line in iter(proc.stdout.readline, b''):
                    logger.debug('async-out: %s', line.strip())
                    line = self.decode(line, encoding, fallback)
                    if callable(on_data):
                        sublime.set_timeout(partial(on_data, line), 0)

                proc.wait()
                logger.debug('async-exit: %s', proc.returncode)
                if proc.returncode == 0:
                    if callable(on_complete):
                        sublime.set_timeout(partial(on_complete, proc.returncode), 0)
                else:
                    if callable(on_error):
                        sublime.set_timeout(partial(on_error, proc.returncode), 0)

            except (OSError, __HOLE__) as e:
                logger.debug('async-exception: %s' % e)
                if callable(on_exception):
                    sublime.set_timeout(partial(on_exception, e), 0)

        thread = threading.Thread(target=partial(async_inner, command, cwd, encoding, **callbacks))
        return thread

    # messages
dataset/ETHPy150Open SublimeGit/SublimeGit/sgit/cmd.py/Cmd.cmd_async