Python记录StreamHandler不会将输出发送到sys.stdout

时间:2019-11-07 08:08:30

标签: python python-3.7 sys

我的python代码:

word-break: break-word;

该代码可以正常工作,直到我们尝试向<style> body { word-break: break-word; } table td { width: 100px; word-break:break-all; } </style> <div class="container"> <div class="row"> <div class="col-12"> <table border="1"> <tbody> <tr> <td>some content</td> <td>http://insertreallylongurlhere</td> </tr> </tbody> </table> </div> </div> </div> 发送一个包含1000行以上的进程。 我们认为在下一次调用 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

之前,python进程没有足够的时间来完成它(I / O写入)。

我们的解决方案是在sys.stdout之后插入 self._cmd_output_logger.info(read) 。但是我们不确定这个问题。或者如果我们有更好的解决方案

0 个答案:

没有答案