From 0b5809c4b5901df60fa6a3d9e1aa12b9c13872ee Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Tue, 10 Apr 2018 21:09:54 +0900 Subject: utils.py: Added _is_main_process() A helper function to identify if we are running in the main process or not. --- buildstream/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'buildstream/utils.py') 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. -- cgit v1.2.1