Skip to content

Commit 507aeca

Browse files
James Boultonclaude
andcommitted
BLEConnection: don't shadow Thread's _stop and _started
On Python 3.11 and 3.12, threading.Thread has a _stop() method and a _started event of its own. BLEConnection, a Thread, used both names for its asyncio stop event and its ready event, so join() called the asyncio.Event and raised TypeError, failing CI on those versions. Python 3.13 changed Thread's internals, so it passed there. Rename them _stop_event and _loop_ready. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 14e04c1 commit 507aeca

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

‎dashio/ble_connection.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ def __init__(self, adapter: str | None = None, context: zmq.Context | None = Non
186186
self._loop: asyncio.AbstractEventLoop | None = None
187187
self._bluez_ready = False
188188
self._registered = False
189-
self._started = threading.Event()
190-
self._stop: asyncio.Event | None = None
189+
self._loop_ready = threading.Event()
190+
self._stop_event: asyncio.Event | None = None
191191

192192
self.tx_zmq_pub = self.context.socket(zmq.PUB)
193193
self.tx_zmq_pub.bind(CONNECTION_PUB_URL.format(id=self.zmq_connection_uuid))
@@ -198,7 +198,7 @@ def __init__(self, adapter: str | None = None, context: zmq.Context | None = Non
198198

199199
self.running = True
200200
self.start()
201-
self._started.wait(5)
201+
self._loop_ready.wait(5)
202202

203203
def add_device(self, device: Device):
204204
"""Add the device to the connection. A BLEConnection has one device, as it advertises its device type.
@@ -267,8 +267,8 @@ async def _shutdown(self):
267267
logger.debug("BLE: unregister failed: %s", error)
268268
self._registered = False
269269
await self._backend.close()
270-
if self._stop is not None:
271-
self._stop.set()
270+
if self._stop_event is not None:
271+
self._stop_event.set()
272272

273273
def _phone_changed(self):
274274
self._quiet_until = self._loop.time() + QUIET_PERIOD
@@ -430,10 +430,10 @@ async def _poll_zmq(self):
430430

431431
async def _main(self):
432432
self._loop = asyncio.get_running_loop()
433-
self._stop = asyncio.Event()
433+
self._stop_event = asyncio.Event()
434434
self._loop.add_reader(self.rx_zmq_sub.getsockopt(zmq.FD), self._zmq_readable)
435435
poller = self._loop.create_task(self._poll_zmq())
436-
self._started.set()
436+
self._loop_ready.set()
437437
try:
438438
await self._backend.start(self, self.adapter)
439439
except BLEError as error:
@@ -453,15 +453,15 @@ async def _main(self):
453453
logger.warning("BLE: couldn't disconnect phones left connected: %s", error)
454454
self._bluez_ready = True
455455
await self._register()
456-
await self._stop.wait()
456+
await self._stop_event.wait()
457457
poller.cancel()
458458
self._loop.remove_reader(self.rx_zmq_sub.getsockopt(zmq.FD))
459459

460460
def run(self):
461461
try:
462462
asyncio.run(self._main())
463463
finally:
464-
self._started.set()
464+
self._loop_ready.set()
465465
self.running = False
466466
self.tx_zmq_pub.close()
467467
self.rx_zmq_sub.close()

0 commit comments

Comments
 (0)