[Pythonmac-SIG] EasyDialogs + Appscript + iPhoto = zombies!

Nathaniel Gray n8gray at gmail.com
Thu Mar 3 04:02:44 CET 2005


Hi,

I've written a small appscript that exports an iPhoto album using the
"album" photo album tool (written in Perl, but I don't have time to
rewrite it... :-/).  I wrote the Python script and installed it as
/Library/Scripts/Applications/iPhoto/iphoto2album so I can use it from
the global Scripts menu.  It works fine, but it leaves a zombie Python
process lying around every time I run it.  I don't know a whole lot
about unix process control, but I found that to avoid zombie processes
you need to "double-fork".  So here's a mock-up of my current code,
mostly copied from
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012:

#### BEGIN
#! /usr/bin/env pythonw
import os, sys
import EasyDialogs as dialogs, datetime
from appscript import *
def main():
    # This is obviously a dummy main function
    errfile = open("/Users/n8gray/ip2a.errors", "w")
    errfile.write("Made it!")
    errfile.close()
    dialogs.Message( "Everything works ok." )

try: 
    pid = os.fork() 
    if pid > 0:
        # exit first parent
        sys.exit(0) 
except OSError, e: 
    print >>sys.stderr, "fork #1 failed: %d (%s)" % (e.errno, e.strerror) 
    sys.exit(1)

# decouple from parent environment
#os.chdir("/")   # I've tried with and without this line.
os.setsid() 
os.umask(0) 

# do second fork
try: 
    pid = os.fork() 
    if pid > 0:
        # exit from second parent, print eventual PID before
        # print "Daemon PID %d" % pid 
        sys.exit(0) 
except OSError, e: 
    print >>sys.stderr, "fork #2 failed: %d (%s)" % (e.errno, e.strerror) 
    sys.exit(1) 

# Open file descriptors
if not sys.stderr: sys.stderr = sys.stdout
si = file('/dev/null', 'r')
so = file('/dev/null', 'a+')
se = file('/dev/null', 'a+', 0)

# Redirect standard file descriptors.
os.dup2(si.fileno(), sys.stdin.fileno())
os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.fileno())

# start the daemon main loop
main()
#### END

Unfortunately, it still produces a zombie after each run and I don't
see the dialog either.  The error log file does get written to,
though, so I know the double-fork succeeds.

Can anybody help me figure out what the problems are?  Also, is there
any way to get rid of all the damn zombie processes on my system
without rebooting?

Thanks,
-n8

-- 
>>>-- Nathaniel Gray -- Caltech Computer Science ------>
>>>-- Mojave Project -- http://mojave.cs.caltech.edu -->


More information about the Pythonmac-SIG mailing list