Mar-04-2018, 12:08 AM
(Mar-03-2018, 11:08 PM)marsokod Wrote:Thank you for your advicebut I'm not sure I have enough knowledge to put all that in a syntax code. Do you have any similar code. Thread +queue(Mar-03-2018, 10:16 PM)ricardons Wrote: Function1() acquires sensor data and show it on lcd Function2() is the same as 1 but also writes the data to a text file So threading?Yes, threading since you will be mostly IO-bound so there is very little risk of suffering from global interpreter lock. Unless Larz60+ has a better solution, I would advise going with the third option I gave you: At the beginning of your code, create 2 queue.Queue() and start 2 threads fetching data from these queues with a timeout. This timeout shall be big enough not to impact your performances with too many loops, but small enough as it will be the time you may have to wait to shut down your program. I run CAN bus monitoring on a Raspberry Pi and had no problem with a loop of 10ms, but 100ms should be even safer. Your serial monitor will just put a meaningful value in the corresponding queue. Your threads will pick this value up and act accordingly. When the main program shuts down, you can put a None value in the queues and make sure that your threads interpret that as a signal they should leave the queue monitoring loop and return. This way, your threads close nicely.