Skip to content

Commit 1fe644b

Browse files
committed
examples: mqtt: fix pub_sub
1 parent 356bf0a commit 1fe644b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

examples/mqtt/pub_sub.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
async def main() -> None:
88
config = enapter.mqtt.Config(host="127.0.0.1", port=1883)
9-
async with enapter.mqtt.Client(config=config) as client:
10-
async with asyncio.TaskGroup() as tg:
11-
tg.create_task(subscriber(client))
12-
tg.create_task(publisher(client))
9+
async with asyncio.TaskGroup() as tg:
10+
client = enapter.mqtt.Client(tg, config=config)
11+
tg.create_task(subscriber(client))
12+
tg.create_task(publisher(client))
1313

1414

1515
async def subscriber(client: enapter.mqtt.Client) -> None:
@@ -28,4 +28,7 @@ async def publisher(client: enapter.mqtt.Client) -> None:
2828

2929

3030
if __name__ == "__main__":
31-
asyncio.run(main())
31+
try:
32+
asyncio.run(main())
33+
except KeyboardInterrupt:
34+
pass

0 commit comments

Comments
 (0)