我的应用程序处理使用Jetson Nano录制视频。录制完成后,依赖于录制功能的返回码,我重命名了视频文件。最近,我注意到有时候,我的日志在重命名行显示一个异常:
021-10-08 20:31:51,421 - root - ERROR - Exception occurred.
Traceback (most recent call last):
File "/home/shozemi/.local/lib/python3.6/site-packages/aiclassroom/capture.py", line 355, in entry
sys.exit(main(args=arguments))
File "/home/shozemi/.local/lib/python3.6/site-packages/aiclassroom/capture.py", line 318, in main
os.rename(output_path, f'{output_path}.failed')
FileNotFoundError: [Errno 2] No such file or directory: '/home/uname/original/division-school_20211008_1936_classroom_75_4659.mp4' -> '/home/uname/original/division-school_20211008_1936_classroom_75_4659.mp4.failed'
但是,当我检查文件夹时,文件确实在那里,并且已经重命名了!
~/original$ ls -la *4659*
-rw-rw-r-- 1 uname uname 1428816762 10月 8 20:21 division-school_20211008_1936_classroom_75_4659.mp4.failed
-rw-rw-r-- 1 uname uname 1122092 10月 8 20:21 division-school_20211008_1936_classroom_75_4659.png
在重命名之前,我还读取了视频文件,并从视频中获取了一个帧作为我的web系统中的缩略图,您可以看到缩略图也正常创建。简而言之:
- 捕获视频= OK
- 从磁盘读取并创建缩略图= OK
- 重命名:日志显示"ERROR"但实际上也是可以的!
谁能给我解释一下?
附加信息:
- OS: Ubuntu 18.04
- 系统:Jetson Nano Python 3.6
考虑
Capture video = OK
Read from disk and create thumbnail = OK
Rename: log says "ERROR" but is actually OK too!
我发现可能由于某种原因,具有相同参数的os.rename
被调用了两次,因此它类似于
os.rename("file1","file2") # file1 exist and is successfully renamed to file2
# potentially other operations
os.rename("file1","file2") # error as file1 no longer exist
需要对/home/shozemi/.local/lib/python3.6/site-packages/aiclassroom/capture.py
进行进一步调查,以确定是否会出现上述情况
由于锁和竞争条件不好,我的脚本被调用了多次。