Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client.connect() just calls connect_async() #4

Closed
jpwsutton opened this issue Feb 4, 2016 · 1 comment
Closed

client.connect() just calls connect_async() #4

jpwsutton opened this issue Feb 4, 2016 · 1 comment

Comments

@jpwsutton
Copy link

migrated from Bugzilla #484733
status UNCONFIRMED severity major in component MQTT-Python for 1.2
Reported in version 1.1 on platform PC
Assigned to: Roger Light

On 2015-12-20 12:06:18 -0500, Jake Callery wrote:

Seems as thought client.connect() simply calls client.connect_async(). This goes against what the docs claim. connect() should be a blocking call. Since it seems to be not, trying to subscribe (like many of the examples out there show) right after a connect call will fail because the connection has not been established before the call to subscribe.

Docs:
https://pypi.python.org/pypi/paho-mqtt#connect-reconnect-disconnect
"The connect() function connects the client to a broker. This is a blocking function. It takes the following arguments:"

Code:
def connect(self, host, port=1883, keepalive=60, bind_address=""):
"""Connect to a remote broker.

    host is the hostname or IP address of the remote broker.
    port is the network port of the server host to connect to. Defaults to
    1883. Note that the default port for MQTT over SSL/TLS is 8883 so if you
    are using tls_set() the port may need providing.
    keepalive: Maximum period in seconds between communications with the
    broker. If no other messages are being exchanged, this controls the
    rate at which the client will send ping messages to the broker.
    """
    self.connect_async(host, port, keepalive, bind_address)
    return self.reconnect()
@ralight
Copy link
Contributor

ralight commented May 23, 2016

This bug report is incorrect, connect() calls reconnect() as described in the report. This is the part that carries out the blocking connect.

@ralight ralight closed this as completed May 23, 2016
mikewadsten added a commit to digidotcom/paho.mqtt.python that referenced this issue Aug 15, 2023
This commit is the result of squashing several intermediate commits.
The individual commit messages were as follows:

Commit message eclipse-paho#1
-----------------

Roll back changes from commit 4910b78.

The commit referenced above removed uses of `socket.error`,
preferring instead to use the Python 3 builtin error types.
This causes various subtle issues with Python 2.7.

In this "revert", I have opted to have the compatibility
`BlockingIOError` be defined as a subclass of IOError, rather than
simply a name alias, because at least within this file, at least,
all uses where we need to check for it. Since `socket.error` is a
subclass of IOError, making `BlockingIOError` a name alias would make
the code more confusing, since it may not be obvious to the reader that
this is the case.

Commit message eclipse-paho#2
-----------------

Bump __version__ to reflect Digi patches have been applied

Commit message eclipse-paho#3
-----------------

Add _on_pre_connect default value of None

Otherwise a client using `.connect_async` will error out.

Commit message eclipse-paho#4
-----------------

Catch and handle socket.error on reconnect calls

Commit message eclipse-paho#5
-----------------

Use select.poll instead of select.select

select.select only works if the fileno values of the given objects
are <1024. In an application that uses or creates hundreds of file
descriptors, one can very easily end up in a situation where the socket
file descriptor is beyond that.

A typical Linux system will have the open file limit for the user set
to 1024, so this generally doesn't happen. But with this change in
place, Paho will function correctly if it does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants