@@ -318,7 +318,7 @@ 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 :
321+ if ics_msg .DescriptionID and receipt_key in self . message_receipts :
322322 receipt_key = (ics_msg .ArbIDOrHeader , ics_msg .DescriptionID )
323323 self .message_receipts [receipt_key ].set ()
324324 if not self ._receive_own_messages :
@@ -477,11 +477,10 @@ def send(self, msg, timeout=0):
477477 else :
478478 raise ValueError ("msg.channel must be set when using multiple channels." )
479479
480- msg_desc_id = next (description_id )
481- message .DescriptionID = msg_desc_id
482- receipt_key = (msg .arbitration_id , msg_desc_id )
483-
484480 if timeout != 0 :
481+ msg_desc_id = next (description_id )
482+ message .DescriptionID = msg_desc_id
483+ receipt_key = (msg .arbitration_id , msg_desc_id )
485484 self .message_receipts [receipt_key ].clear ()
486485
487486 try :
@@ -492,5 +491,9 @@ def send(self, msg, timeout=0):
492491 # If timeout is set, wait for ACK
493492 # This requires a notifier for the bus or
494493 # some other thread calling recv periodically
495- if timeout != 0 and not self .message_receipts [receipt_key ].wait (timeout ):
496- raise CanTimeoutError ("Transmit timeout" )
494+ if timeout != 0 :
495+ got_receipt = self .message_receipts [receipt_key ].wait (timeout )
496+ # We no longer need this receipt, so no point keeping it in memory
497+ del self .message_receipts [receipt_key ]
498+ if not got_receipt :
499+ raise CanTimeoutError ("Transmit timeout" )
0 commit comments