Why is my wnck.screen_get_default() call hanging or crashing when launched through upstart?

When I run the following script manually, everything works fine. However, when I launch it on-boot through Upstart via a shell script (which launches the script as root) it successfully gets to the wnck.screen_get_default() line and never goes beyond it. Upstart keeps respawning the script over and over (since it keeps dying) and no exceptions are thrown. Any ideas?

import gtk
import wnck
import time

def cycle():
        print("ABOUT TO RUN screen_get_default!!")
        screen = wnck.screen_get_default()
        print("JUST RAN screen_get_default!!")
    except Exception as e:

print("STARTING APP!!")

while 1 == 1:

The upstart script looks like the following:

description "myapp"
start on runlevel [12345]
stop on runlevel [!12345]
exec /usr/lib/myapp/myapp.sh
post-stop exec sleep 10

EDIT: I ran exec sudo python /usr/lib/myapp/myapp.py from the upstart script and now I am finally getting a meaningful error in the log file, but I can't decipher where to go from here:

GtkWarning: IA__gdk_x11_display_get_xdisplay: assertion 'GDK_IS_DISPLAY (display)' failed
  screen = wnck.screen_get_default()
/usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display
  warnings.warn(str(e), _gtk.Warning)