python - 在 OSX 上使用 python select kqueue 来监视外部应用程序的文件创建

标签 python macos file-io epoll kqueue

通常,将我的 1 小时长的录音 session 转码为 mp3 文件需要二十多分钟。

当 OSX 应用程序 garageband 完成写入该 mp3 文件时,我想使用 python 脚本执行一系列 python 代码。

在 python 中检测外部应用程序完成向文件写入数据并关闭该文件的最佳方法是什么?我阅读了有关 kqueue 和 epoll 的内容,但由于我没有操作系统事件检测方面的背景知识,也找不到一个很好的例子,所以我在这里要求一个例子。

我现在使用的代码执行以下操作,我正在寻找更优雅的代码。

while True:
    try:
        today_file = open("todays_recording.mp3","r")
        my_custom_function_to_process_file(today_file)
    except IOError:
         print "File not ready yet..continuing to wait"

最佳答案

您可以打开 lsof 并按您感兴趣的进程或文件进行过滤...

关于python - 在 OSX 上使用 python select kqueue 来监视外部应用程序的文件创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4777739/

相关文章:

python - 为什么只有在运行完整的测试套件时 django 测试才会失败?

python - 无法使用 Python 类函数作为按钮命令

macos - 在 NSViewController 和 NSTableViewDelegate 之间共享方法

objective-c - NSArrayController 和异常 "CoreData could not fulfill a fault"

c++ - 创建 BMP 文件

python - 在Python中配置类的最优雅的方式是什么?

python - 有没有办法使用 pymysql 将数据帧插入到 mysql 中?

macos - 从 XPC bundle 中检索沙箱权利

c - 如何使用 C 语言中的 fscanf() 读取 .gro 文件?

c++ - 二进制读/写运行时失败