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

Nathaniel Gray n8gray at gmail.com
Tue Mar 8 01:45:19 CET 2005

I sent this last week and haven't seen it come through on the list
yet.  Sorry if it's a duplicate...

---------- Forwarded message ----------
From: Nathaniel Gray <n8gray at gmail.com>
Date: Wed, 2 Mar 2005 19:02:44 -0800
Subject: EasyDialogs + Appscript + iPhoto = zombies!
To: Pythonmac-Sig <pythonmac-sig at python.org>


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

#### 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!")
    dialogs.Message( "Everything works ok." )

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

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

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

# 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
#### 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?


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

More information about the Pythonmac-SIG mailing list