Can't spawn, or popen from daemon

Mark Roach mrroach at okmaybe.com
Tue Apr 20 13:19:13 EDT 2004


I am using the daemonize (double-fork) code from the cookbook, and have
bumped into a strange issue. This is what my program is doing:

def main():
    ... useful things ...
    os.popen('/usr/bin/lp -d printer1 %s' % (filename))

def daemonize(func):
    """cookbook recipe from
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012"""

    ... cut 'n paste code ...

    #Additional closing of stdio

    sys.stdin.close()
    sys.stdout.close()
    sys.stderr.close()

    # this is pretty obscure!
    os.close(0)
    os.close(1)
    os.close(2)

if __name__ == '__main__':
    daemonize(main)

The thing that's strange is that the call to lp never happens... if I
replace daemonize(main) with just main() it works as expected. Is there
some secret requirement on stdin/out for popen/spawn/system calls? I
have tried all three, and they all work when I don't double-fork, but
don't when I do. I can't figure this out at all, and it doesn't help
matters that the problem only occurs in a situation where it is very
hard to debug...

Thanks,

Mark




More information about the Python-list mailing list