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

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to