It has no thread of its own so it can't do heart beating etc work if you aren't using it in some way at the time, as you have noticed.
In this old thread, I noted that you can effectively do what the underlying impl does, and if run the 'wait' method yourself periodically with a low timeout if you aren't actually using it, to essentially provoke 'use' and allow it opportunity to do processing such as heartbeating: https://lists.apache.org/thread.html/rf1afdd45b5a3c25e8ccdba58f8e15cd569764483f858ceb6967612e1%40%3Cusers.qpid.apache.org%3E Of course this requires your thread to be free periodically so you can still do that. As you noticed, you can't multi-thread the connection, it is inherently single threaded as most of Proton is. The mail thread contains a reference to another that they created, which discusses the more regular 'Container' stuff along with 'EventInjector' etc. The container is given its own thread and does such processing implicitly itself. You can pass work to it from another thread if needed. Robbie On Mon, 8 Feb 2021 at 14:31, Johannes Wienke <[email protected]> wrote: > > Hi, > > what is the intended way of supporting long-running tasks using a > BlockingConnection in Python? Without calling the run method of the > connection, my broker (ActiveMQ Artemis) terminates a client session > after 60 seconds. I can call the run method and then the connections is > kept alive. However, then my main thread is blocked and I can no longer > send (the infrequent) messages. Calling run on a different thread > results in a segfault. > > Here is a simple reproduction case, assuming a running ActiveMQ Artemis > with user "root" and password "password": > > ----- > > import time > from uuid import uuid4 > > from proton import Message > from proton.utils import BlockingConnection > > conn = BlockingConnection("localhost:5672", user="root", > password="password") > sender = conn.create_sender("test") > > sender.send(Message(body=b"somedata", id=uuid4())) > > print("First message send. Waiting...") > > time.sleep(65) > > print("Sending second message") > sender.send(Message(body=b"failing", id=uuid4())) > > ----- > > The second send call will fail > > This is the threaded version that I tried, which immediately segfaults: > > ----- > > from threading import Thread > import time > from uuid import uuid4 > > from proton import Message > from proton.utils import BlockingConnection > > conn = BlockingConnection("localhost:5672", user="root", > password="password") > > conn_thread = Thread(target=conn.run) > conn_thread.start() > > try: > sender = conn.create_sender("test") > > sender.send(Message(body=b"somedata", id=uuid4())) > > print("First message send. Waiting...") > > time.sleep(65) > > print("Sending second message") > sender.send(Message(body=b"failing", id=uuid4())) > finally: > conn.close() > conn_thread.join(10) > > ----- > > Kind regards > Johannes > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
