diff --git a/pyra2yr/pyra2yr/network.py b/pyra2yr/pyra2yr/network.py index c4694e8..8f915de 100644 --- a/pyra2yr/pyra2yr/network.py +++ b/pyra2yr/pyra2yr/network.py @@ -94,6 +94,7 @@ def __init__(self, uri: str, timeout=5.0): self.task = None self._tries = 15 self._connect_delay = 1.0 + self._lock = asyncio.Lock() def open(self): self.task = asyncio.create_task(async_log_exceptions(self.main())) @@ -103,8 +104,9 @@ async def close(self): await self.task async def send_message(self, m: str) -> aiohttp.WSMessage: - await self.in_queue.put(m) - return await self.out_queue.get() + async with self._lock: + await self.in_queue.put(m) + return await self.out_queue.get() async def main(self): # send the initial message