does anyone know a trick to force pymol to wait from within a python script to complete resizing and drawing the canvas?

I used cmd.refresh and cmd.rebuild in various places in the script, but the raytracing still only shows part of the images. I suspect that the cmd.viewport command is the culplrit because the canvas is only resized after the whole script ran, thus causing only part of the image to appear. Interestingly I never had these problems if I ran the same scene as a .pml file.

I am running pymol 0.99.rc8 under Linux.