1

I'm currently working on a project that includes a software package written by the graduate student who was here before me. In short, the package is a control system for a piece of hardware and has two separate applications that run concurrently- Module1 and Module2. Clunky, but it works just fine for now.

My current issue deals with getting these two Python programs to 'talk' to each other. Module1 is a control panel of sorts, and Module2 is a live-output plot of the data collection taking place. If a certain variable in Module1's class is true, I need Module2 to be able to read this and react accordingly. Module1 has a Tkinter framework, and Module2 is built with PyQt, if it helps.

bearplane
  • 700
  • 1
  • 9
  • 22

2 Answers2

0

One approach is to have them participate in a pub-sub system, where publishers issue commands and subscribers react to them.

Consider 0mq or kafka.

J_H
  • 17,926
  • 4
  • 24
  • 44
0

If both programs are running on the same machine and you're using linux, you can use a named pipe, which is a special type of file for sharing information between processes. See Python read named PIPE for a simple example of how to use named pipes. I recommend working through the example to see if it serves your purpose. You can read the documentation of how to create a named pipe in python here if the example is insufficient: https://docs.python.org/3/library/os.html#os.mkfifo

To implement your particular case, you could modify Module1 to send a message to the named pipe containing the value of the variable whenever the variable's value changed. You might do this in the class method that sets the variable's value. Separately, you could modify Module2 to periodically check if there are data in the named pipe. If there are data, retrieve the data and use the variable values retrieved to make Module2 react as desired.

Application threading is unrelated to the use of a named pipe. Named pipes should work regardless of the framework you are using. You should think of a named pipe as a file that one application is writing to, and at the same time, the other application is reading from.

Seth Difley
  • 1,330
  • 1
  • 23
  • 33