-1

I would like to establish a very simple communication between two python scripts. I have decided that the best way to communicate and to have both scripts read from a text file. I would like the main program to wait while to child programs execute.

Normally I would make the main program wait x amount of time and continuously check the text file for an okay flag. However I have seen people talk about using a signal.

Could someone please give an example of this.

  • http://pymotw.com/2/subprocess/ provides an example of using signal. Look at the Signaling Between Processes subsection. – Vinod Sharma Mar 22 '15 at 08:43
  • 1. Why do you use `subprocess` instead of importing the corresponding modules and calling the necessary function directly (possibly using `threading`, `multiprocessing` modules)? 2. There are many IPC methods and the reading from a text file on receiving a signal might not be the best option e.g., you could use pipes to exchange data between processes instead. – jfs Mar 22 '15 at 09:12

2 Answers2

0

There is Popen.send_signal() method that allows you to send a signal to a child process.

Here's code example that sends SIGINT to ping subprocess to get the summary in the output on exit.

Community
  • 1
  • 1
jfs
  • 399,953
  • 195
  • 994
  • 1,670
-1

You need one process to write and one to read; both processes reading leads to no communication. Signals are used only for special proposes, not for normal inter-process-communication. Use something like pipes or sockets. It's not more complicated than files, but much more powerful.

Daniel
  • 42,087
  • 4
  • 55
  • 81