Skip to content

Commit

Permalink
Merge pull request #7218 from dalthviz/fixes_issue_7158
Browse files Browse the repository at this point in the history
PR: Limit length of serialized values in Variable Explorer when applying modifications
  • Loading branch information
ccordoba12 authored May 28, 2018
2 parents b3e7b81 + 8804236 commit 0fe5c98
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion spyder/widgets/variableexplorer/namespacebrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)"""
Expand Down Expand Up @@ -294,7 +297,16 @@ 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"),
_("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))
Expand Down

0 comments on commit 0fe5c98

Please sign in to comment.