Avoid duplicate file open/close activity in the common case of updating the stats file under the lock. Instead, check if the file exists and open it with r+ mode to make in-place edits. Otherwise, if the file does not exist, open it with w mode to write the initial stats.
Avoid duplicate file open/close activity in the common case of updating the stats file under the lock. Instead, check if the file exists and open it with
r+
mode to make in-place edits. Otherwise, if the file does not exist, open it withw
mode to write the initial stats.