Home > database >  Git for Windows Python print not working when DEBUG/LOG too?
Git for Windows Python print not working when DEBUG/LOG too?

Time:10-12

When I run my Python script, my print statements do not get written to the output/screen (see output below). However, in a normal Windows console/prompt (and macOs) it works: both log and print messages are written to stdout (mixed).

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

When I it CRTL-C the the text from 'before api init' onwards get printed (so after program execution).

Code:

# 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()

Maybe it has to do with the multiprocessing part?

CodePudding user response:

It's more than likely that buffering of output is to blame. Try flushing and messages should show up

# for stdout
sys.stdout.flush()

# for stderr
sys.stderr.flush()
  • Related