Python Logging StreamHandler doesn't send output to sys.stdout

138
November 08, 2019, at 00:30 AM

My python code:

def _init_cmd_logger(self):
    # Init streamer
    stream_handler = logging.StreamHandler()
    stream_handler.setLevel(logging.DEBUG)
    formatter = logging.Formatter('%(message)s')
    stream_handler.setFormatter(formatter)
    # Configure logger
    cmd_output_logger = logging.getLogger(self._ansible_command)
    cmd_output_logger.propagate = False
    cmd_output_logger.handlers = []
    cmd_output_logger.addHandler(stream_handler)
    return cmd_output_logger
def _live_output_manage(self, popen):
    stdout = []  # Var with std out
    stderr = []  # Var with std err
    # Print outout while executing
    while True:
        reads = [popen.stdout.fileno(), popen.stderr.fileno()]
        ret = select.select(reads, [], [])
        for filed in ret[0]:
            if filed == popen.stdout.fileno():
                read = popen.stdout.readline().strip()
                if read != '':
                    self._cmd_output_logger.info(read)
                    self._logger.debug(read)
                    stdout.append(read)
            if filed == popen.stderr.fileno():
                read = popen.stderr.readline().strip()
                if read != '':
                    self._cmd_output_logger.error(read)
                    self._logger.error(read)
                    stderr.append(read)
        # A None value indicates that the process hasnt terminated yet
        if popen.poll() is not None:
            break
    # A None value indicates that the process has terminated correctly
    return_code = popen.wait()
    return return_code, stdout, stderr

The Code works fine, until we try to send to sys.stdout a process with more than 1000 lines. We are thinking that the python process doesn't have enough time to finish it (I/O writes), before the next call to self._cmd_output_logger.info(read)

Our solution was insert time.sleep(*) after logger.info() . But we are not sure about the issue. Or if we could have a better solution

Rent Charter Buses Company
READ ALSO
Different dimensions error in the Feautured pipelines

Different dimensions error in the Feautured pipelines

I am a total newbie in ML,and I am currently trying to create a pipeline for my dataBut the thing is, when I ran it,I received error:

117
How to get the key from OrderedDict in python

How to get the key from OrderedDict in python

I have a below OrderedDict in python:

181
how to get value in python using by the address of sent from c++?

how to get value in python using by the address of sent from c++?

In C++, i take a int typed variable and pass it's address to pythonThe address is hexadecimal and passed to python as string

129
Is there a proper variable to track how many times a loop has looped?

Is there a proper variable to track how many times a loop has looped?

I'm pretty new to coding, so forgive me if this is super obvious

112