I am working on a Python script that sets up communication between multiple Electronic Control Units (ECU1 and ECU2) using the python-can library. The script is designed to read messages from a BLF file, filter them based on specific IDs, and handle them using separate threads for each ECU. However, the script does not terminate as expected and seems to get stuck after printing “main_ECU done”,”filtering done”,”ECU1 Thread has finished”.
script flow:
- main_ecu fucntion – reads the message and send to virtual bus
- ecu_filter function – filter the messages based on ID and stop when ID ‘oxDE0Q is Received
- ‘main’ function – create virtual bus, use threading as shown below
def main():
bus = can.interface.Bus(interface='virtual', channel='0', bitrate=500000,receive_own_messages=True)
can_id_filter_ecu1 = [0xKEREE, 0xWJKL0, oxDE0Q]
can_id_filter_ecu_2 = [0xIOBF, oxDE0Q]
main_ECU(bus, "input.blf")
#two seperate threads for ecu 1 and ecu 2
ecu_thread_1 = threading.Thread(target=ecu_filter,args= (bus,can_id_filter_ecu1,"File_1_msg.asc",))
ecu_thread_2 = threading.Thread(target=ecu_filter, args=(bus,can_id_filter_ecu_2,"File_2_msg.asc",))
ecu_thread_1.start()
ecu_thread_2.start()
ecu_thread_1.join()
print("ECU1 Thread has finished.")
ecu_thread_2.join()
print("ECU2 Thread has finished.")
bus.shutdown()
The Output is as below
===============
main_ECU done
filtering done
ECU1 Thread has finished.
Why might the script not be terminating?
what is the issue with ecu_thread_2?is multithreading working properly?