hope you guys can help me. I searched a lot but was not able to find a solution for my problem.
I am using a Raspberry 3 B+ to communicate to a safety plc with a constant cycle time of 2ms. To satisfy my needs I used the Preempt-RT Patch for the Linux Kernel and worked with an accurate microsecond timing of this link:
How to get millisecond and microsecond-resolution timestamps in Python
With isolcpus and the taskset command I isolated two cpus for my pyhton script to avoid longer cycle times caused by the operating system. Receiving and sending some bits via the GPIOs of the Raspberry with a 2ms cycle time is my first task and works fine now.
The second task is to read and write the information to a MySQL database, which is not time critical (the database connection works fine already). I therefore thought of using a queue which could be the connection between my fast task and the slow database-task.
However, here is my problem. If I use Concurrent Future ThreadPoolExecutor, I can easily use a queue but by 2ms time is, as expected, completely destroyed. Therefore I thought of using the ProcessPoolExecutor to use both isolated cpus and splitting the two tasks to one cpu each. But there are two questions I cannot solve:
I want to assign the fast task to one cpu and the slow task to the second cpu (both cpus are isolated). How can I accomplish that?
I need two queues (Transmit, Receive) to communicate. I was not able to find a way to communicate between two processes in both directions.
I also thought of using two different scripts that i can add to a cpu independently, but here is again the problem of communicating between those scripts.
Is there a way to solve this problem? By the way, I am completely new to python and hope I am able to understand your ideas. ;-)
If someone has the same problem in the future: I solved the problem with the use of ZeroMQ to communicate between two independent scripts. I set up a bidirectional communication with Publish/Subscribe Messaging Pattern. See: https://learning-0mq-with-pyzmq.readthedocs.io/en/latest/pyzmq/patterns/pubsub.html