python - 用于 Windows Python 的 Git 打印在 DEBUG/LOG 时也不起作用?
问题描述
当我运行我的 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 时,从“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()
也许它与多处理部分有关?
解决方案
输出缓冲很可能是罪魁祸首。尝试刷新和消息应该出现
# for stdout
sys.stdout.flush()
# for stderr
sys.stderr.flush()
推荐阅读
- javascript - 如何将现有菜单变成响应式下拉菜单?
- javascript - 为什么我的选择器没有展开并显示其中的所有选项?
- python - 在 matplotlib 中生成 16 位颜色图
- regex - 如何在 Google 表格中合并具有相同 ID 的行?
- html - 如何使用 VBA 在 IE 页面上单击按钮
- ios - 重叠的 UICollectionView 单元格
- javascript - 我不明白这个语法
- spring - 空指针异常的Spring警报邮件系统
- python-3.x - numpy/ma/core.py 中 MemoryError 的来源
- css - 如何实现颜色 B = 颜色 A 应用 30% 黑色 (#000000) 透明度