我在python中使用以下命令打开文件:
file = os.path.normpath(file_path)
phandler = subprocess.Popen(['open', '-W', file])
我在投票
^{pr2}$查看进程是否已终止。如果进程是用cmd+Q终止的,它是有效的。但是,如果我用cmd+w关闭文件,这是不起作用的。有什么万无一失的方法来确保文件不再打开。在
从phandler,我也可以使用幻影器pid如果需要的话。在
如果没有其他方法可以做到这一点,我可能不得不使用像watchdog这样的库,它是iNotify的包装器,但是如果我可以使用像psutils这样的库来实现这一点,那就更好了。在
你要找的是这样的东西:
根据Python:Non-Blocking + Non defunct process和how to kill (or avoid) zombie processes with subprocess module,似乎需要communicate()调用来处理Linux中的“僵尸”进程(我认为,在MacOS中也是如此)。在
(请参阅StackOverflow的Tag Info for zombie-process tag。)
这将产生如下输出:
^{pr2}$相关问题 更多 >
编程相关推荐