Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix python3.6 compatibility #57

Merged
merged 1 commit into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion asyncio_mqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,12 @@ def _pending_calls(self) -> Generator[int, None, None]:

async def connect(self, *, timeout: int = 10) -> None:
try:
loop = asyncio.get_running_loop()
# get_running_loop is preferred, but only available in python>=3.7
try:
loop = asyncio.get_running_loop()
except AttributeError:
loop = asyncio.get_event_loop()

# [3] Run connect() within an executor thread, since it blocks on socket
# connection for up to `keepalive` seconds: https://git.io/Jt5Yc
await loop.run_in_executor(
Expand Down
2 changes: 1 addition & 1 deletion tests/reconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def main():
format="%(asctime)s %(levelname)s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
asyncio.run(asyncio.wait([test(), tick()]))
asyncio.get_event_loop().run_until_complete(asyncio.wait([test(), tick()]))


if __name__ == "__main__":
Expand Down