summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-02-13 10:53:16 +0000
committerBenjamin Schubert <ben.c.schubert@gmail.com>2019-02-13 14:59:47 +0000
commitb41a82d3b535b679320dea7541d7b0211944750c (patch)
treef419d960cf771ea836a7666b712e118265244f07
parentec4bbf35a159b5d019d6acd84aa5753b794bb7ee (diff)
downloadbuildstream-bschubert/cleanup-local-state.tar.gz
Don't register exceptions when not running the testsuitebschubert/cleanup-local-state
This fix a problem with the garbage collector not being able to clean the MetaElements that are loaded. On small projects this is not a problem, but in bigger projects, this can save a few hundred of MBs at runtime The reason behind this is, whenever we have a "stack" element, which has no stack.yaml configuration, since it doesn't need it, we would get an exception thrown when initiating the first one, as loading the yaml file would fail. This would capture the frame in which this command was executed, which references meta_elements. Therefore, as long as another exception is not thrown, the garbage collector would not be able to clean all the MetaElements.
-rw-r--r--buildstream/_exceptions.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/buildstream/_exceptions.py b/buildstream/_exceptions.py
index 0797e7207..8728f6e69 100644
--- a/buildstream/_exceptions.py
+++ b/buildstream/_exceptions.py
@@ -19,6 +19,7 @@
# Tiago Gomes <tiago.gomes@codethink.co.uk>
from enum import Enum
+import os
# Disable pylint warnings for whole file here:
# pylint: disable=global-statement
@@ -50,6 +51,9 @@ def get_last_exception():
# Used by regression tests
#
def get_last_task_error():
+ if 'BST_TEST_SUITE' not in os.environ:
+ raise BstError("Getting the last task error is only supported when running tests")
+
global _last_task_error_domain
global _last_task_error_reason
@@ -67,11 +71,12 @@ def get_last_task_error():
# tests about how things failed in a machine readable way
#
def set_last_task_error(domain, reason):
- global _last_task_error_domain
- global _last_task_error_reason
+ if 'BST_TEST_SUITE' in os.environ:
+ global _last_task_error_domain
+ global _last_task_error_reason
- _last_task_error_domain = domain
- _last_task_error_reason = reason
+ _last_task_error_domain = domain
+ _last_task_error_reason = reason
class ErrorDomain(Enum):
@@ -126,7 +131,8 @@ class BstError(Exception):
self.reason = reason
# Hold on to the last raised exception for testing purposes
- _last_exception = self
+ if 'BST_TEST_SUITE' in os.environ:
+ _last_exception = self
# PluginError