Still problems running script from cron

William R. Dickson wrd at awenet.com
Thu Apr 27 19:17:41 EDT 2000


Hi all,

I posted a while ago about a script that runs fine from the command 
line, but hangs when run from cron.  I've made progress, but am not all 
the way there yet.  Many people suggested helpful ways to redirect 
stdout into files, but they had no effect.  I eventually managed to get 
past the point where it was hanging by changing:

os.system("%s -c %s -n %s -o %s %s" % (webalizer, conffile, self.server, 
outputdir, self.currlog))

to:

rv = os.system("%s -c %s -n %s -o %s %s" % (webalizer, conffile, 
self.server, outputdir, self.currlog))

It then stopped hanging there.  Now it hangs when my forks are supposed 
to close, here:


children = 1

for server in servers:
  child = os.fork()
  if child == 0:            # Fork returns 0 in the child; if this is now
    break                   # a child, we want out of the loop.
  else:
    children = children+1   # Otherwise, we check to see if we're already
    if children > C:        # at the max number of processes; if not, we
      rv = os.wait()        # go to the top of the loop and fork another.
      children = children-1 # Otherwise, we wait until a fork closes.



The end of the child process looks like this:


# When both server stats and user stats are completed, we can finally get
# rid of the daily log and close the fork.
    
os.remove(nicelog)
      
print ("+ %s  %s %s: No problems detected; closing fork."
       % (strftime(T, localtime(time())), procdate, id))

sys.exit()  # I've also tried using return here with no change


When run from cron, the message "No problems detected; closing fork." 
prints as expected, but the child process never closes, according to ps.  
When run from the command line, it closes as expected.

Any idea why this might happen?

Thanks,

-Bill



More information about the Python-list mailing list