0
logging.info("outside try, except and finally block")
try:
    logging.info("inside try block")
except:
    logging.info("inside except block")
finally:
    logging.info("inside finally block")
    os._exit(1)

Initializing boto3 session and pushing log to cloudwatch using watchtower library in python. if os._exit(1) is used in the program Only logging.info("outside try, except and finally block") log is pushed into cloudwatch. So I tried sys.exit() now all the logs are pushed into cloudwatch.

logging.info("outside try, except and finally block")
try:
    logging.info("inside try block")
except:
    logging.info("inside except block")
finally:
    logging.info("inside finally block")
    sys.exit()

Not understanding what is happening with os._exit(1)

Chand
  • 51
  • 7
  • Does this answer your question? [What is difference between sys.exit(0) and os.\_exit(0)](https://stackoverflow.com/questions/9591350/what-is-difference-between-sys-exit0-and-os-exit0) – jordanm May 27 '21 at 14:43
  • sys.exit flushes buffers but os._exit does not. – jordanm May 27 '21 at 14:43

0 Answers0