This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Reading umask (thread-safe)
Type: Stage: resolved
Components: Versions:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: guettli, serhiy.storchaka, vstinner
Priority: normal Keywords:

Created on 2018-11-19 10:38 by guettli, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg330083 - (view) Author: Thomas Guettler (guettli) * Date: 2018-11-19 10:38
Up to now there is no thread way to read the umask in Python

https://stackoverflow.com/questions/53227072/reading-umask-thread-safe

You can use this pattern:

current_umask = os.umask(0)  # line1
os.umask(current_umask)      # line2
return current_umask

A thread which executes between line1 and line2 will have a different umask.

I would be great, if the python standard library would provide correspondig thread safe method.

Related question at stackoverflow: https://stackoverflow.com/questions/53227072/reading-umask-thread-safe
msg330084 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-11-19 11:08
There is no thread way to read the umask in C as well. The os module provides thin wrappers to the POSIX API. os.umask() acts exactly as a C function umask(). If thread safe method be added in the POSIX API we can expose it in the os module.
msg330085 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-11-19 11:32
Maybe the Python documentation can be enhanced to document functions which are known to have a side-effect "process-wide" vs "thread-safe" functions. For example, signal.pthread_sigmark() affects the current thread, wheras locale.setlocale() is process-wide.

See "POSIX Safety Concepts" of the glibc:

https://www.gnu.org/software/libc/manual/html_node/POSIX-Safety-Concepts.html#POSIX-Safety-Concepts

Example with setlocale, "MT-Unsafe":

https://www.gnu.org/software/libc/manual/html_node/Setting-the-Locale.html
msg330087 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-11-19 11:34
My own (incomplete) list of "process-wide states":
https://vstinner.readthedocs.io/threads.html#process-wide
msg330094 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-11-19 11:50
Ok, let's move to bpo-35276: "Document thread safety".
History
Date User Action Args
2022-04-11 14:59:08adminsetgithub: 79456
2018-11-19 11:50:30vstinnersetmessages: + msg330094
2018-11-19 11:34:00vstinnersetmessages: + msg330087
2018-11-19 11:32:26vstinnersetnosy: + vstinner
messages: + msg330085
2018-11-19 11:08:53serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg330084

resolution: wont fix
stage: resolved
2018-11-19 10:38:14guettlicreate