Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] python paho-mqtt 1.1 connect() not blocking?

Hi Randy,

I've just tried the same code but against test.mosquitto.org - both
with and without client certificates - and it worked fine for me.
Maybe you could try that yourself - if you want a client certificate
for test.mosquitto.org, directly send me a CSR generated from
something like:

openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key

It's worth noting that if you call subscribe() immediately after
connect(), then in the event your client reconnects in loop_forever()
then the subscriptions won't be renewed (assuming you have
clean_session=True as you do), so doing your subscriptions in
on_connect() is a good strategy.

Cheers,

Roger



On Mon, Dec 14, 2015 at 4:43 AM, Randy Forbes <randy.forbes@xxxxxxxxx> wrote:
> Thanks for the reply Roger.
>
> My apologies up front as I'm quite the newbie to Python; long time C#
> developer; hopefully you won't hold that against me. ;-)  Based on your
> reply, I did a bit of studying up on the Python code and have a bit of a
> better understanding.
>
> I'm not sure I'd mentioned, I'm using the AWS IoT. Here the code sample that
> I'm using: https://gist.github.com/shweta-nerake1/8684968ebacb5522c86a
>
> What had me thinking async was putting a print("hello world") immediately
> after connect() and before subscribe(). That print was invoked prior to
> receiving the on_connect() callback. Would totally make sense in what you
> said that it's establishing the TCP connection but perhaps not receiving the
> CONNACK yet.
>
> I'm still unable to get subscribe() working in having it immediately after
> connect() though. Moving the subscribe() into on_connect() definitely works.
>
> Outside of the Gist above, I was able to find another web reference that
> this should work. At a bit of a loss. I was able to replicate the issue on
> my Mac so at least eliminated anything to do within the Raspberry Pi.
>
> Any other thoughts or things to investigate, happy to do so. My Python
> debugging skills are essentially non-existent so it'll take me a bit to see
> what's really going on at the lower layers. Looking forward to learning
> that. I'll keep plugging away.
>
> Thanks!
>
> On Saturday, December 12, 2015, Roger Light <roger@xxxxxxxxxx> wrote:
>>
>> Hi Randy,
>>
>> connect() is definitely blocking, but maybe not in quite the way you are
>> thinking. It blocks until the TCP connection with the server in complete,
>> but this doesn't mean that the mqtt CONNECT/CONNACK flow is complete.
>>
>> This shouldnt actually matter though, because calling subscribe()
>> immediately after connect() should work fine. What error do you get?
>>
>> Are you calling loop_start() or loop_forever() after the call to
>> subscribe?
>>
>> Cheers,
>>
>> Roger
>>
>> On 11 Dec 2015 01:29, "Randy Forbes" <randy.forbes@xxxxxxxxx> wrote:
>>>
>>> python: 3.4.2
>>> paho-mqtt: 1.1
>>> os: raspian-jessie
>>>
>>> According to the following documentation:
>>> https://pypi.python.org/pypi/paho-mqtt/1.1 the connect() call is supposed to
>>> be a blocking function.
>>>
>>> **********
>>> The connect() function connects the client to a broker. This is a
>>> blocking function.
>>> **********
>>>
>>> In my usage of the library, this appears to not be the case. I attempted
>>> to execute a subscribe() immediately after a connect but was not successful
>>> in getting subscribed. Moving the subscribe into onconnect() did work but
>>> indicated that the documentation may be incorrect.
>>>
>>> In viewing the source, it appears that connect() calls into
>>> connect_async() which would make it a non-blocking call.
>>>
>>> Am I correct in my observations?
>>>
>>> Kind Regards.
>>>
>>> Randy Forbes
>>>
>>> _______________________________________________
>>> paho-dev mailing list
>>> paho-dev@xxxxxxxxxxx
>>> To change your delivery options, retrieve your password, or unsubscribe
>>> from this list, visit
>>> https://dev.eclipse.org/mailman/listinfo/paho-dev
>
>
> _______________________________________________
> paho-dev mailing list
> paho-dev@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from
> this list, visit
> https://dev.eclipse.org/mailman/listinfo/paho-dev


Back to the top