qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andi welchlin <andi.welch...@gmail.com>
Subject Re: QPID Proton 0.19 Python: Exit MessagingHandler.run()
Date Thu, 22 Feb 2018 09:46:06 GMT
Yes, sure:

#!/usr/bin/env python3

from proton.reactor import Container
from proton.handlers import MessagingHandler
from proton import Message, Connection

import threading
import sys

class AmqpReceiver(MessagingHandler):
    def __init__(self):
        super().__init__(prefetch=50)
        self.host = "localhost:9001"

        self.container = Container(self)
        self.conn = None
        self.receiver = None
        self.thread = threading.Thread(target=self.run)
        self.thread.daemon = True
        self.thread.start()

    def on_message(self, event):
        print("got message: event: ", event.message)

    def on_start(self, event):
        print("on start")
        self.conn = self.container.connect(self.host, reconnect=False)
        self.receiver = self.container.create_receiver(self.conn,
"test.awe.queue")

    def run(self):
        print("run container")
        self.container.run()
        print("after container.run()")
        sys.stdout.flush()

    def _stop(self):
        print('call stop')
        self.container.stop()
        print('call join')
        self.thread.join()
        print('done stop')

    def on_connection_closed(self, event):
        print("on_connection_closed")

    def on_session_closed(self, event):
        print("on_session_closed")

    def on_link_closed(self, event):
        print("on_link_closed")

    def on_disconnected(self, event):
        print("on_disconnected")


try:
    handler = AmqpReceiver()
    input("press enter")
    handler._stop()
except Exception as ex:
    print("got EXCEPTION")
    print(ex)



On Thu, Feb 22, 2018 at 9:32 AM, Gordon Sim <gsim@redhat.com> wrote:

> On 22/02/18 08:05, andi welchlin wrote:
>
>> Hello all,
>>
>> I tried to stop the Proton MessagingHandler by calling
>> self.container.stop() but this causes an endless loop (cpu goes to 100%).
>>
>> So I just could help myself to throw an exception. But I think this is not
>> a good solution.
>>
>> Can someone tell me, how I can leave container.run() gracefully?
>>
>
> If all connections it is managing are closed and there are no timed events
> pending, it should exit by itself.
>
> Do you have an example you can share showing the problem?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message