0

I am using websockets library in my Python project. However the websocket library is raising connection exception when I hit Ctrl+C as follows:

Exception in thread Thread-1: Traceback (most recent call last): File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner self.run() File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 1073, in run self.function(*self.args, **self.kwargs) File "client.py", line 95, in <lambda> self.keepAliveTimer = Timer(15, lambda: self.sendKeepAlive()) File "client.py", line 91, in sendKeepAlive self.ws.send(message) File "/Users/username/Library/Python/2.7/lib/python/site-packages/websocket/_app.py", line 156, in send "Connection is already closed.") WebSocketConnectionClosedException: Connection is already closed. 

However, the timestamp is not getting printed. What should I do that all the uncaught exceptions are printed with timestamp on stdout?

I don't need fix for this exception as I know the reason. My query is to get this as well as other exceptions printed on stdout with the timestamp.

6
  • Please post example code that can generate this error. There's no context. Commented Feb 27, 2021 at 10:23
  • I don't want to fix this error as I know the reason. I just want it as well as all exceptions to be printed with the timestamp. Commented Feb 27, 2021 at 10:27
  • 2
    Use logging, catch the exception, and log it with the timestamp. Alternatively, catch the exception and print your own timestamp. Commented Feb 27, 2021 at 10:29
  • @ShashwatKumar, you can catch exception, add there timestamp and raise it. Commented Feb 27, 2021 at 10:29
  • 1
    @ShashwatKumar, take a look on this answer. Commented Feb 27, 2021 at 10:31

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.