Skip to content

Commit

Permalink
Fix python3.6 compatibility (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
fipwmaqzufheoxq92ebc authored Apr 7, 2021
1 parent 8deaaee commit f7e1d23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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

0 comments on commit f7e1d23

Please sign in to comment.