From b9165de6b2b930c52e9c0402da4a25b249ba0dde Mon Sep 17 00:00:00 2001 From: menshibin Date: Mon, 12 Aug 2024 22:55:35 +0800 Subject: [PATCH] modify alert sql --- docs/examples/python/tmq_native.py | 17 +++++++++-------- docs/examples/python/tmq_websocket_example.py | 13 +++++++------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/docs/examples/python/tmq_native.py b/docs/examples/python/tmq_native.py index 32a21d2780..64e447384c 100644 --- a/docs/examples/python/tmq_native.py +++ b/docs/examples/python/tmq_native.py @@ -142,17 +142,17 @@ def seek_offset(consumer): raise err # ANCHOR_END: assignment - -# ANCHOR: unsubscribe def unsubscribe(consumer): + # ANCHOR: unsubscribe try: consumer.unsubscribe() print("Consumer unsubscribed successfully."); except Exception as err: print(f"Failed to unsubscribe consumer. ErrMessage:{err}") - - -# ANCHOR_END: unsubscribe + finally: + if consumer: + consumer.close() + # ANCHOR_END: unsubscribe if __name__ == "__main__": consumer = None @@ -162,9 +162,10 @@ if __name__ == "__main__": subscribe(consumer) seek_offset(consumer) commit_offset(consumer) - unsubscribe(consumer) + consumer.unsubscribe() + print("Consumer unsubscribed successfully."); except Exception as err: print(f"Failed to stmt consumer. ErrMessage:{err}") finally: - if consumer: - consumer.close() \ No newline at end of file + consumer.unsubscribe() + diff --git a/docs/examples/python/tmq_websocket_example.py b/docs/examples/python/tmq_websocket_example.py index e22f2d595b..aa9cbf6545 100644 --- a/docs/examples/python/tmq_websocket_example.py +++ b/docs/examples/python/tmq_websocket_example.py @@ -143,14 +143,17 @@ def commit_offset(consumer): # ANCHOR_END: commit_offset # -# ANCHOR: unsubscribe + def unsubscribe(consumer): +# ANCHOR: unsubscribe try: consumer.unsubscribe() print("Consumer unsubscribed successfully."); except Exception as err: print(f"Failed to unsubscribe consumer. ErrMessage:{err}") - + finally: + if consumer: + consumer.close() # ANCHOR_END: unsubscribe @@ -161,10 +164,8 @@ if __name__ == "__main__": consumer = create_consumer() subscribe(consumer) seek_offset(consumer) - commit_offset(consumer) - unsubscribe(consumer) + commit_offset(consumer) except Exception as err: print(f"Failed to stmt consumer. ErrorMessage:{err}") finally: - if consumer: - consumer.close() \ No newline at end of file + unsubscribe(consumer); \ No newline at end of file