This tool made me wait .006 seconds without a reason
roadelou opened this issue · comments
In the src/video-loggin.py file, in the folder_sort and trash_videos functions, the for loops have an unexplained sleep time :
for file in os.listdir():
time.sleep(.001)
I guess this is an aesthetic thing for the progress bar, but it might be worth putting a comment to explain it, else this looks very surprising.
Sure, should have put a comment to explain this! It is only needed in trash_videos
, when checking the duration of the files. When I do not wait each time, errors are raised, maybe because files are opened and closed too fast?
Anyway, I deleted the useless instances and put a comment in trash_videos
.
I tried removing the time.sleep, but I cannot reproduce the bug with trash_videos.
One note though : waiting an arbitrary amount of time to make a bug disappear should only be used as a last resort. I imagine that you tried solving it another way but did not succeed and that is why you put a sleep here. Sometimes (especially if the bug comes from another library) it cannot be avoided, but 90% of the time you should wait for something to solve the bug.
I trust that you already knows what I wrote below, but I do have to put my markdown to use or I might get rusty 😆
The reason to avoid that practice is quite obvious : If the bug occurs because a specific action takes some time to complete, then the amount of time that the action takes will vary a little between runs. In the worst case, that can manifest itself as a bug that appears sometimes, for reasons seemingly unrelated to your code (the best kind of bugs, as everyone knows 😄).
Another thing that makes sleep frowned upon is that the computer used for development and the one used for production can have widely different hardware (and OS), hence the amount of time that made the bug disappear in development might be too small (or absurdly too large) for production. This means you might end up with random bugs in production (or on the users computer) that just never appear in development.
Hence, it is best practice to investigate what causes your bug and find out what you are really waiting for.
Then again, not everything has to be Fort Nox 😉