I know this pattern to read the umask in Python:
current_umask = os.umask(0) # line1
os.umask(current_umask) # line2
return current_umask # line3
But this is not thread-safe.
A thread which executes between line1 and line2 will have a different umask.
Is there a thread-safe way to read the umask in Python?
Related: https://bugs.python.org/issue35275
if your system has
Umask
field in/proc/[pid]/status
, you could read from on it:tested under CentOS 7.5, Debian 9.6.
or, you could add a thread lock :)