diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-04-10 21:09:54 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-04-10 21:11:54 +0900 |
commit | 0b5809c4b5901df60fa6a3d9e1aa12b9c13872ee (patch) | |
tree | 85bb6d9882ab7a4d73805a805b4320827f2451e5 | |
parent | 888f0b9fda31e8a63b01b9aa5b695010249b8ffa (diff) | |
download | buildstream-0b5809c4b5901df60fa6a3d9e1aa12b9c13872ee.tar.gz |
utils.py: Added _is_main_process()
A helper function to identify if we are running in the main process
or not.
-rw-r--r-- | buildstream/utils.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/buildstream/utils.py b/buildstream/utils.py index 40705346b..5b246ced4 100644 --- a/buildstream/utils.py +++ b/buildstream/utils.py @@ -536,6 +536,18 @@ def save_file_atomic(filename, mode='w', *, buffering=-1, encoding=None, # to distinguish between a kwarg set to None and an unset kwarg. _sentinel = object() +# Main process pid +_main_pid = os.getpid() + + +# _is_main_process() +# +# Return whether we are in the main process or not. +# +def _is_main_process(): + assert _main_pid is not None + return os.getpid() == _main_pid + # Recursively remove directories, ignoring file permissions as much as # possible. |