1

I have a Perl script that launches some programs and then ends while the programs run in the background. I would like to write a Python script that will be able to wait for those launched programs to finish, not just for the Perl script.

I tried this:

import subprocess

subprocess.call(('./perl_script.pl'))

and this:

import subprocess

p = subprocess.Popen(('./perl_script.pl'))
p.wait()

but in both cases program finishes when the perl_script.pl finishes, and not when the launched programs do.

Luise
  • 31
  • 1
  • 5
  • 2
    Why not just wait in the perl script until the launched programs end? That sounds a lot easier than controlling programs from one script that were launched in another. – Padraic Cunningham Apr 03 '15 at 01:44
  • Traditionally unix doesn't support this; orphaned processes are inherited by the init process. But see http://stackoverflow.com/questions/6476452/process-re-parenting-controlling-who-is-the-new-parent. (Hard to see how you'd utilize that for your use case, especially from python.) – Gil Hamilton Apr 03 '15 at 02:40
  • @GilHamilton: `prctl(PR_SET_CHILD_SUBREAPER)` can be called in Python using `ctypes`. But I would try `shell=True` and redirecting stdin/stdout/stderr first. – jfs Apr 03 '15 at 19:48
  • the problem is that I don't know PERL and it's a very long script... (yay for old scripts from phd advisors) – Luise Apr 04 '15 at 00:12

0 Answers0