John wrote:
> Hello,

Hi John,

I didn't see a response to your question, so I'll make an attempt ...

>  
> I've written a script which conducts several subprocess calls and then
> ultimately calls a shell script which runs even more programs... my
> script is using subprocess to execute a few sed calls, and then execute
> the script. I'm getting strange behavior:

Just a suggestion, if you find you are preforming sed replace operations
regularly, you might consider writing your own sed-like replace
function. This way you avoid spawning a subprocess altogether for
search/replace functionality, and as an added bonus you can re-use it in
future scripts. The following (untested) code should get you started, if
you choose to go this route:

import re

def sed_replace(search, replace, text):
    pattern = re.compile(search)
    return pattern.sub(replace, text)

def infile_sed_replace(search, replace, path):
    text = file(path).read()
    newtext = sed_replace(search, replace, text)
    file(path, 'w').write(newtext)

...
infile_sed_replace('RunMin=[0-9][0-9]*', 'RunMin=%s' % k, runFile)
...

> 
> You'll notice, the last subprocess call is commented out. Right now I'm
> just getting to that point to make sure everything is working. So, it
> seems to work, but I'm not sure how to get it to work if I change the
> command to nohup. I still want python to wait for it to return, in fact,
> I would like to set the python job running in the background as well...
> so what I'm looking at doing is:
>  
> % nohup myControl.py
>    ---> which will make several subprocess.call(s) including some that
> should be 'nohupped' as well...

This strikes me as nohup abuse, though I'm not entirely certain what you
are trying to accomplish. Since you plan to nohup *and* background your
script anyway, you might be better served by preemptively detaching from
the controlling terminal (or daemonizing) instead. If so, you may find
one or both of the following recipes useful:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012

Of course, you may need to handle logging a little differently.

HTH,
Marty
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to