Sometimes it would be happened that my services (which started manually in tmux or screen) will be stop by getting an unknown or other kinds of exceptions that I didn't handle them. In my case date & time of exceptions event is so important.
So how to get date & time of exceptions in Python errors? Like running a service in tmux or screen and wait to see the results which it will print.
To solve this issue, we can try to use sys.excepthook like so:
import sys
import traceback
import datetime
def err(type, value, tb):
print("Exception date time: {}".format(datetime.datetime.now()))
print(traceback.print_tb(tb))
sys.excepthook = err
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With