0

My today's task is to create a Python script (say A.py) which can do the following things:

  • Start a C program (say CProg) passing some params
  • Start another Python script (say B.py) passing other params
  • Join/Wait until B.py has finished
  • Send a SIGINT to CProg
  • Iterate (this won't be a problem at all I think :P)

Since I'm pretty new in developing Python scripts and my mind is quite full of C/C++ thread/join/execve/... I'd like to ask you if there's a proper way to accomplish my task. I've read some related topics on SO (some talk about PIPEs or Execl) but I'm not sure what to use yet.

Thanks in advance

Cob013
  • 1,057
  • 9
  • 22
  • 1
    LOL ... have you given A.py an attempt at all? if you are used to threads in C the principles are the same in any language... http://stackoverflow.com/questions/2846653/python-multithreading-for-dummies has a bunch of starting point answers for you – Ahmed Masud Jun 20 '13 at 10:16

1 Answers1

1

Use subprocess module.

import os
import signal
import subprocess
import sys

params = [...]
for param for params:
    proc = subprocess.Popen(['/path/to/CProg', param.., param..])
    subprocess.call([sys.executable, 'B.py', param.., param...])
    os.kill(proc.pid, signal.SIGINT)
    proc.wait()
falsetru
  • 357,413
  • 63
  • 732
  • 636