Пример #1
0
def callSpinfer(cmd,timeout =900,enc='utf-8'):
    output = ''
    errors = ''
    # logging.debug(cmd)
    my_timer = None
    with Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True,encoding=enc) as p:
        try:
            start = datetime.datetime.now()
            memusage = getAllChildMe(p.pid)
            # isExit = False
            while(memusage != 0.0):
                end = datetime.datetime.now()
                elapsed = end - start
                if(elapsed.seconds > timeout):
                    raise TimeoutExpired(cmd,timeout)
                memusage = getAllChildMe(p.pid)
                # print(str(p.pid) + " ; " + str(memusage))
                if memusage > 2000:
                    # isExit = True
                    raise TimeoutExpired(cmd,timeout)

            output, errors = p.communicate(timeout=timeout)
            # print(output)
            logging.debug(cmd + '\t' +output)
            # logging.info(errors)
            if errors:
                raise CalledProcessError(errors, '-1')
            output
        except CalledProcessError as e:
            logging.debug(cmd +'\t'+ errors)
        except TimeoutExpired as t:
            # my_timer.cancel()


            childrenProcess = []
            getChildMem(p.pid, childrenProcess)
            [killP(i) for i in childrenProcess]

            p.terminate()
            p.communicate()
            # p.kill()
            logging.warning(cmd +'\t'+str(t))
    return output,errors
Пример #2
0
def shellGitCheckout(cmd, enc='utf-8'):
    try:
        with Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True,
                   encoding=enc) as p:
            output, errors = p.communicate()
            # print(output)
            if errors:
                raise CalledProcessError(errors, '-1')
            output
    except CalledProcessError as e:
        logging.warning(errors)
    return output, errors
Пример #3
0
def shellGitCheckout(cmd, timeout=600, enc='utf-8'):
    output = ''
    errors = ''
    # logging.debug(cmd)

    with Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True, encoding=enc) as p:
        try:
            output, errors = p.communicate(timeout=timeout)
            # print(output)
            logging.debug(cmd + '\t' + output)
            # logging.info(errors)
            if errors:
                raise CalledProcessError(errors, '-1')
            output
        except CalledProcessError as e:
            logging.debug(cmd + '\t' + errors)
        except TimeoutExpired as t:
            p.terminate()
            p.communicate()
            # p.kill()
            logging.warning(cmd + '\t' + str(t))
    return output, errors
Пример #4
0
def shellCallTemplate(cmd, enc='utf-8'):
    try:
        with Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True,
                   encoding=enc) as p:
            output, errors = p.communicate()
            # print(output)
            if errors:
                m = re.search(
                    'unknown revision or path not in the working tree', errors)
                if not m:
                    raise CalledProcessError(errors, '-1')
            output
    except CalledProcessError as e:
        logging.warning(errors)
    return output