Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Limit length of serialized values in Variable Explorer when applying modifications #7218

Merged
merged 2 commits into from
May 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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