0

My application deals with recording video using Jetson Nano. After recording, depends on the return code of the recording function, I rename the video file. Recently, I noticed that sometime, my log shows an exception at the renaming line:

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'

However, when I check the folder, the file is indeed there, and has already been renamed!

~/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

Before renaming, I also read the video file and get a frame from the video as the thumbnail on my web system, and you can see the thumbnail is created normally too. So in a nutshell:

  • Capture video = OK
  • Read from disk and create thumbnail = OK
  • Rename: log says "ERROR" but is actually OK too!

Can someone explain it for me?


Additional information:

  • OS: Ubuntu 18.04
  • System: Jetson Nano
  • Python 3.6
  • why do you try to rename it with the `failed` ext ? Why the 2 files have a very big size difference ? – balderman Oct 08 '21 at 12:49
  • @balderman The file extension `.failed` is for another part of my system which looks for those extensions and do some stuffs with them. Size difference is obvious, one is a video and the other is an image. – Nghia Truong Oct 11 '21 at 06:10

2 Answers2

1

Considering

Capture video = OK
Read from disk and create thumbnail = OK
Rename: log says "ERROR" but is actually OK too!

I find probable that for some reason os.rename with same arguments is called twice, thus it is something like

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

Further inquiry of /home/shozemi/.local/lib/python3.6/site-packages/aiclassroom/capture.py would be required to determine if described situation could arise

Daweo
  • 31,313
  • 3
  • 12
  • 25
  • That was the first thing came to my mind, but I couldn't find any other place where `os.rename` is called. Another probability is that somehow my script is called twice, but I could not find any evidence of that either. – Nghia Truong Oct 11 '21 at 06:12
0

It turned out that my script was called multiple times due to bad locking and race condition.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 08 '21 at 03:54