Skip to content

Commit 10b9a94

Browse files
James Boultonclaude
andcommitted
Device: make the publishing socket before the thread starts
The socket was made in run(), so a control update or reply sent straight after creating a Device could find no tx_zmq_pub (AttributeError). On CI's Python 3.11 runner, test_button_group_tap_sends_its_buttons hit it every time. It's now made and bound in __init__. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8a73095 commit 10b9a94

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎dashio/device.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,9 @@ def __init__(
833833
self.zmq_connection_uuid = "DVCE:" + shortuuid.uuid()
834834
self._b_zmq_connection_uuid = self.zmq_connection_uuid.encode()
835835
self.context = context or zmq.Context.instance()
836+
# Made before the thread starts, so the device can send as soon as it's created.
837+
self.tx_zmq_pub = self.context.socket(zmq.PUB)
838+
self.tx_zmq_pub.bind(CONNECTION_PUB_URL.format(id=self.zmq_connection_uuid))
836839
self._wifi_rx_callback = None
837840
self._dashio_rx_callback = None
838841
self._name_rx_callback = None
@@ -1023,8 +1026,6 @@ def _store_registry(self) -> list[dict]:
10231026
def run(self):
10241027
# Continue the network loop, exit when an error occurs
10251028

1026-
self.tx_zmq_pub = self.context.socket(zmq.PUB)
1027-
self.tx_zmq_pub.bind(CONNECTION_PUB_URL.format(id=self.zmq_connection_uuid))
10281029
self.rx_zmq_sub = self.context.socket(zmq.SUB)
10291030
self.rx_zmq_sub.setsockopt(zmq.SUBSCRIBE, b"\tWHO")
10301031
self.rx_zmq_sub.setsockopt(zmq.SUBSCRIBE, b"COMMAND")

0 commit comments

Comments
 (0)