You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by pe...@apache.org on 2021/09/09 08:16:39 UTC

[pulsar] 06/09: [Python] Expose Client.shutdown() method (#11955)

This is an automated email from the ASF dual-hosted git repository.

penghui pushed a commit to branch branch-2.8
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit b1ff9bc7a3cf84a3bf9f2d981c5051bd0b1f6f64
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Tue Sep 7 18:36:11 2021 -0700

    [Python] Expose Client.shutdown() method (#11955)
    
    ### Motivation
    
    Similar to what we expose in Java and C++ client, we should expose the quick `shutdown()` method on the Python client.
    
    (cherry picked from commit c11ac895a1a90a378e4407597ec9540ff8bdcdd4)
---
 pulsar-client-cpp/python/pulsar/__init__.py |  9 +++++++++
 pulsar-client-cpp/python/pulsar_test.py     | 13 +++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/pulsar-client-cpp/python/pulsar/__init__.py b/pulsar-client-cpp/python/pulsar/__init__.py
index 429aa10..9570cbe 100644
--- a/pulsar-client-cpp/python/pulsar/__init__.py
+++ b/pulsar-client-cpp/python/pulsar/__init__.py
@@ -844,6 +844,15 @@ class Client:
         _check_type(str, topic, 'topic')
         return self._client.get_topic_partitions(topic)
 
+    def shutdown(self):
+        """
+        Perform immediate shutdown of Pulsar client.
+
+        Release all resources and close all producer, consumer, and readers without waiting
+        for ongoing operations to complete.
+        """
+        self._client.shutdown()
+
     def close(self):
         """
         Close the client and all the associated producers and consumers
diff --git a/pulsar-client-cpp/python/pulsar_test.py b/pulsar-client-cpp/python/pulsar_test.py
index 7c85f77..b7d265f 100755
--- a/pulsar-client-cpp/python/pulsar_test.py
+++ b/pulsar-client-cpp/python/pulsar_test.py
@@ -1134,6 +1134,19 @@ class PulsarTest(TestCase):
         self.assertTrue(msg.topic_name() in partitions)
         client.close()
 
+    def test_shutdown_client(self):
+        client = Client(self.serviceUrl)
+        producer = client.create_producer('persistent://public/default/partitioned_topic_name_test')
+        producer.send(b'hello')
+        client.shutdown()
+
+        try:
+            producer.send(b'hello')
+            self.assertTrue(False)
+        except pulsar.PulsarException:
+            # Expected
+            pass
+
     def test_negative_acks(self):
         client = Client(self.serviceUrl)
         consumer = client.subscribe('test_negative_acks',