2014-09-01 73 views
1

我遇到的问题实际上是在查看器中产生了显示图像的子流程。基本上我打开堆栈中的图片,并希望显示它们一段时间,然后杀死子进程。运行程序时,它显示的图片是想要的,但我无法得到实际的.kill.terminate函数的工作。Python子流程不会终止

class ImageDisplay(ThreadParent): 
    def __init__(self, label): 
     ThreadParent.__init__(self, label) 
    def display_image(self): 
     image = ThreadParent.image_stack.pop(0) 
     cwd = os.getcwd() 
     # Automagically opens in preview @ osx 
     p = subprocess.Popen(["open", "file://%s/%s" % (cwd, 
      filepath(filename(image)))]) 
     disptime = displaytime(image) 
     print("Displaying image:", image, "for", disptime, "seconds..") 
     time.sleep(disptime) 
     p.terminate() 
     p.kill() 

所有帮助将不胜感激。

所有最优秀的

回答

1

我认为open将终止预览打开后,这意味着你没有句柄预览程序。尝试调用预览二进制,而不是像:

/Applications/Preview.app/Contents/MacOS/Preview /path/to/image.jpg 

HTH