Python子进程不会终止

Python子进程不会终止,python,image,macos,process,subprocess,Python,Image,Macos,Process,Subprocess,我在实际终止生成的子进程以在查看器中显示图像时遇到问题。基本上,我是从堆栈中打开图片,并希望显示它们一段时间,然后终止子进程。当运行程序时,它会显示所需的图片,但我无法获得实际的.kill或.terminate功能 class ImageDisplay(ThreadParent): def __init__(self, label): ThreadParent.__init__(self, label) def display_image(self):

我在实际终止生成的子进程以在查看器中显示图像时遇到问题。基本上,我是从堆栈中打开图片,并希望显示它们一段时间,然后终止子进程。当运行程序时,它会显示所需的图片,但我无法获得实际的
.kill
.terminate
功能

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()
我们将非常感谢您的帮助


所有最好的

我认为打开将在预览打开后终止,这意味着您没有预览程序的句柄。尝试调用预览二进制文件,如:

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