I've not had much luck with either Link.on_ready_to_send or Link.on_connect, the latter of which I noticed was the method used in the performance examples.
The server thread is running long before the client message thread is spawned, and the two are able to send messages if a delay between the thread startup and message transmission is present.
How can I reliably time the first transmission as soon as SnakeMQ is ready?
Kind regards,
Mike
Just a small update:
I logged the value of Link._do_loop on Thread.start(), however sending a message after asserting _do_loop is True still results in a lost message - so far the most reliable way of determining messages get through is just sleeping 200ms before the initial message.
Any ideas?
# need to wait a bit before closing socket
#time.sleep(1)
messctl.stop()
With a sleep it works fine, but when commented, message is not send. I would like to ask a proper way to identify when snakemq instance is ready to close loop/send next message.
Your guess was almost correct. MasterMessenger is just a wrapper for snakemq. Instance is running in separate thread.
I'm creating a CLI module for a server, so behavior is following:
- start CLI
- open connection in background
- parse arguments
- send command
- close connection
- exit
It seems not really pythonic way to sleep (with no guaranty of message delivery) instead of knowing exactly, when connection could be closed. E.g. when the server or network is really busy, I should wait not 1 second, but probably 5 (or 10).
That's the reason I'm asking.
Could you please give me some example of code, which will wait for message delivery and then close connection?