fix: clarify _send_packet()/_send_ack() scheduling contract (#263)

Replace misleading bare 'pass' with explicit comment explaining that
PacketTrack polling is handled by PacketSendSchedulerThread /
AckSendSchedulerThread.  Restructure condition to
'if not (scheduler and scheduler.is_alive()):' so the fallback
thread is only started when the scheduler is genuinely unavailable.

Closes #244
This commit is contained in:
2026-08-28 14:50:18 -04:00
committed by GitHub
parent 08deaab94e
commit a1c28bf46f
2 changed files with 15 additions and 12 deletions
+2
View File
@@ -18,6 +18,8 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Fix deprecated datetime.utcfromtimestamp()/utcnow() calls — replace with timezone-aware equivalents [`e7b0a19`](https://github.com/craigerl/aprsd/commit/e7b0a19)
- Fix _send_packet()/_send_ack(): replace misleading `pass` with explicit comment explaining PacketTrack polling contract; restructure condition to `if not (scheduler and scheduler.is_alive()):` [`2842851`](https://github.com/craigerl/aprsd/commit/2842851)
- Add reset() to @singleton decorator; update tests to use ClassName.reset() instead of ClassName.instance = None [`ef19aaa`](https://github.com/craigerl/aprsd/commit/ef19aaa)
- Fix PacketTrack.keys/items/values — return list snapshots instead of live dict views outside the lock [`088436e`](https://github.com/craigerl/aprsd/commit/088436e)
+13 -12
View File
@@ -68,13 +68,15 @@ def send(packet: core.Packet, direct=False, aprs_client=None):
@msg_throttle_decorator.sleep_and_retry
def _send_packet(packet: core.Packet, direct=False, aprs_client=None):
if not direct:
# Use threadpool scheduler instead of creating individual threads
# The packet was already registered in PacketTrack via
# collector.PacketCollector().tx(packet) in send() before this
# function was called. PacketSendSchedulerThread polls PacketTrack
# every second and will find the packet there — nothing more needs
# to be done here. The scheduler is started (or confirmed alive)
# as a side-effect of _get_packet_scheduler().
scheduler = _get_packet_scheduler()
if scheduler and scheduler.is_alive():
# Scheduler will handle the packet
pass
else:
# Fallback to old method if scheduler not available
if not (scheduler and scheduler.is_alive()):
# Fallback: scheduler failed to start — send directly in a thread
thread = SendPacketThread(packet=packet)
thread.start()
else:
@@ -84,13 +86,12 @@ def _send_packet(packet: core.Packet, direct=False, aprs_client=None):
@ack_throttle_decorator.sleep_and_retry
def _send_ack(packet: core.AckPacket, direct=False, aprs_client=None):
if not direct:
# Use threadpool scheduler instead of creating individual threads
# Same implicit handoff as _send_packet: the ack was registered in
# PacketTrack before this call; AckSendSchedulerThread polls and
# picks it up. Starting/verifying the scheduler is all that's needed.
scheduler = _get_ack_scheduler()
if scheduler and scheduler.is_alive():
# Scheduler will handle the packet
pass
else:
# Fallback to old method if scheduler not available
if not (scheduler and scheduler.is_alive()):
# Fallback: scheduler failed to start — send directly in a thread
thread = SendAckThread(packet=packet)
thread.start()
else: