Skip to content

Commit

Permalink
Merge pull request #2 from Edanflame/main
Browse files Browse the repository at this point in the history
修改on_error函数
  • Loading branch information
vnpy committed Sep 24, 2021
2 parents a9b96f1 + 921a906 commit 93c8512
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions vnpy_websocket/websocket_client.py
Expand Up @@ -129,16 +129,25 @@ def on_packet(self, packet: dict):
"""收到数据回调"""
pass

def on_error(self, exception_type: type, exception_value: Exception, tb):
def on_error(
self,
exception_type: type,
exception_value: Exception,
tb
) -> None:
"""触发异常回调"""
sys.stderr.write(
self.exception_detail(exception_type, exception_value, tb)
)
return sys.excepthook(exception_type, exception_value, tb)
try:
print("WebsocketClient on error" + "-" * 10)
print(self.exception_detail(exception_type, exception_value, tb))
except Exception:
traceback.print_exc()

def exception_detail(
self, exception_type: type, exception_value: Exception, tb
):
self,
exception_type: type,
exception_value: Exception,
tb
) -> str:
"""异常信息格式化"""
text = "[{}]: Unhandled WebSocket Error:{}\n".format(
datetime.now().isoformat(), exception_type
Expand Down

0 comments on commit 93c8512

Please sign in to comment.