Git为Windows Python打印不工作时,DEBUG/LOG ?



当我运行Python脚本时,我的print语句没有被写入输出/屏幕(参见下面的输出)。然而,在正常的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

当我按ctrl - 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()

最新更新