From b8e867c5d73f963e6fe59b5a6fda0cb3667c3298 Mon Sep 17 00:00:00 2001 From: dalthviz Date: Mon, 28 May 2018 12:06:53 -0500 Subject: [PATCH 1/2] Limit length of serialized value in Variable Explorer when saving. --- spyder/widgets/variableexplorer/namespacebrowser.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/spyder/widgets/variableexplorer/namespacebrowser.py b/spyder/widgets/variableexplorer/namespacebrowser.py index 9fa3389c0c3..e2a1f33b7fe 100644 --- a/spyder/widgets/variableexplorer/namespacebrowser.py +++ b/spyder/widgets/variableexplorer/namespacebrowser.py @@ -45,6 +45,9 @@ # To be able to get and set variables between Python 2 and 3 PICKLE_PROTOCOL = 2 +# Maximum length of a serialized variable to be set in the kernel +MAX_SERIALIZED_LENGHT = 1e6 + class NamespaceBrowser(QWidget): """Namespace browser (global variables explorer widget)""" @@ -294,7 +297,15 @@ def set_value(self, name, value): # We need to enclose values in a list to be able to send # them to the kernel in Python 2 svalue = [cloudpickle.dumps(value, protocol=PICKLE_PROTOCOL)] - self.shellwidget.set_value(name, svalue) + + # Needed to prevent memory leaks. See issue 7158 + if len(svalue) < MAX_SERIALIZED_LENGHT: + self.shellwidget.set_value(name, svalue) + else: + QMessageBox.warning(self, _("Warning"), + _("For performance reasons is not " + "possible to save the changes " + "made to the variable")) except TypeError as e: QMessageBox.critical(self, _("Error"), "TypeError: %s" % to_text_string(e)) From 8804236e77b151485d1639d435a1e6d4c70972ee Mon Sep 17 00:00:00 2001 From: dalthviz Date: Mon, 28 May 2018 12:46:34 -0500 Subject: [PATCH 2/2] Change warning message for serialized variable length. --- spyder/widgets/variableexplorer/namespacebrowser.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spyder/widgets/variableexplorer/namespacebrowser.py b/spyder/widgets/variableexplorer/namespacebrowser.py index e2a1f33b7fe..f5973bfbd65 100644 --- a/spyder/widgets/variableexplorer/namespacebrowser.py +++ b/spyder/widgets/variableexplorer/namespacebrowser.py @@ -303,9 +303,10 @@ def set_value(self, name, value): self.shellwidget.set_value(name, svalue) else: QMessageBox.warning(self, _("Warning"), - _("For performance reasons is not " - "possible to save the changes " - "made to the variable")) + _("The object you are trying to modify is " + "too big to be sent back to the kernel. " + "Therefore, your modifications won't " + "take place.")) except TypeError as e: QMessageBox.critical(self, _("Error"), "TypeError: %s" % to_text_string(e))