【问题标题】:Git for Windows Python print not working when DEBUG/LOG too?调试/日志时,Windows Python 的 Git 打印也不起作用?
【发布时间】:2021-11-27 21:26:49
【问题描述】:

当我运行 Python 脚本时,我的打印语句不会被写入输出/屏幕(请参阅下面的输出)。但是,在普通的 Windows 控制台/提示(和 macOS)中它可以工作:日志和打印消息都写入标准输出(混合)。

DEBUG:session_storage:session:getter: MainThread
DEBUG:urllib3.connectionpool:Resetting dropped connection: example.com
DEBUG:urllib3.connectionpool:https://example.com:443 "GET /QW/7720d5b252de HTTP/1.1" 200 1073
before api init
!!setting session
b
after api init
after request init
Process  X-1  is running.
Got a valid value from queue

当我使用 CRTL-C 时,从 'before api init' 开始的文本会被打印出来(所以在程序执行之后)。

代码:

# SETUP LOGGING
logging.basicConfig(level=logging.DEBUG)

def main():

  #another process is created via multiprocessing (process duplicated?)
  ...

  logger = logging.getLogger(__name__)

if __name__ == '__main__':
  main()

也许它与多处理部分有关?

【问题讨论】:

  • 与git无关,所以去掉标签

标签: python windows printing output


【解决方案1】:

输出缓冲很可能是罪魁祸首。尝试刷新,应该会显示消息

# for stdout
sys.stdout.flush()

# for stderr
sys.stderr.flush()

【讨论】:

  • 我会试试的(一旦我可以访问我的另一台计算机)
  • 这行得通。谢谢。
猜你喜欢
  • 1970-01-01
  • 2016-05-21
  • 2013-01-05
  • 2011-08-30
  • 2017-11-05
  • 1970-01-01
  • 2020-12-05
  • 2014-01-25
  • 2021-10-17
相关资源
最近更新 更多