summaryrefslogtreecommitdiff
path: root/src/buildstream/utils.py
diff options
context:
space:
mode:
authorBenjamin Schubert <bschubert15@bloomberg.net>2019-12-06 18:18:55 +0000
committerBenjamin Schubert <bschubert15@bloomberg.net>2019-12-09 11:28:48 +0000
commit6ff95c7495e66ced931a062169504dfb0af5d7c9 (patch)
treee2318af0f5ffdd98611773eaa24d2031040f9c4b /src/buildstream/utils.py
parent2745a2872ebf5df8ace68ddc389868ca1699b759 (diff)
downloadbuildstream-bschubert/add-isolated-tests.tar.gz
utils.py: Rework `is_main_process` to allow for running the cli in a subprocessbschubert/add-isolated-tests
This will allow us a better isolation for tests, as we would now be able to run them in subprocesses.
Diffstat (limited to 'src/buildstream/utils.py')
-rw-r--r--src/buildstream/utils.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/buildstream/utils.py b/src/buildstream/utils.py
index b6716a29d..a3cd96d1d 100644
--- a/src/buildstream/utils.py
+++ b/src/buildstream/utils.py
@@ -56,7 +56,8 @@ _ALIAS_SEPARATOR = ":"
_URI_SCHEMES = ["http", "https", "ftp", "file", "git", "sftp", "ssh"]
# Main process pid
-_MAIN_PID = os.getpid()
+# This is expected to be set by bst `cli()`
+_MAIN_PID = None
# The number of threads in the main process at startup.
# This is 1 except for certain test environments (xdist/execnet).
@@ -770,6 +771,15 @@ def _pretty_size(size, dec_places=0):
return "{size:g}{unit}".format(size=round(psize, dec_places), unit=unit)
+# _set_as_main_process()
+#
+# Mark the current process at the
+#
+def _set_as_main_process():
+ global _MAIN_PID
+ _MAIN_PID = os.getpid()
+
+
# _is_main_process()
#
# Return whether we are in the main process or not.