@@ -318,8 +318,9 @@ def _process_msg_queue(self, timeout=0.1):
318318 if is_tx :
319319 if bool (ics_msg .StatusBitField & ics .SPY_STATUS_GLOBAL_ERR ):
320320 continue
321- if ics_msg .DescriptionID :
322- receipt_key = (ics_msg .ArbIDOrHeader , ics_msg .DescriptionID )
321+
322+ receipt_key = (ics_msg .ArbIDOrHeader , ics_msg .DescriptionID )
323+ if ics_msg .DescriptionID and receipt_key in self .message_receipts :
323324 self .message_receipts [receipt_key ].set ()
324325 if not self ._receive_own_messages :
325326 continue
@@ -477,11 +478,10 @@ def send(self, msg, timeout=0):
477478 else :
478479 raise ValueError ("msg.channel must be set when using multiple channels." )
479480
480- msg_desc_id = next (description_id )
481- message .DescriptionID = msg_desc_id
482- receipt_key = (msg .arbitration_id , msg_desc_id )
483-
484481 if timeout != 0 :
482+ msg_desc_id = next (description_id )
483+ message .DescriptionID = msg_desc_id
484+ receipt_key = (msg .arbitration_id , msg_desc_id )
485485 self .message_receipts [receipt_key ].clear ()
486486
487487 try :
@@ -492,5 +492,9 @@ def send(self, msg, timeout=0):
492492 # If timeout is set, wait for ACK
493493 # This requires a notifier for the bus or
494494 # some other thread calling recv periodically
495- if timeout != 0 and not self .message_receipts [receipt_key ].wait (timeout ):
496- raise CanTimeoutError ("Transmit timeout" )
495+ if timeout != 0 :
496+ got_receipt = self .message_receipts [receipt_key ].wait (timeout )
497+ # We no longer need this receipt, so no point keeping it in memory
498+ del self .message_receipts [receipt_key ]
499+ if not got_receipt :
500+ raise CanTimeoutError ("Transmit timeout" )
0 commit comments