Skip to content

Commit

Permalink
Merge from 3.x: PR #7234
Browse files Browse the repository at this point in the history
Fixes #7157
Fixes #5830
  • Loading branch information
ccordoba12 committed Jun 7, 2018
2 parents 6d4958c + 1c4d9d5 commit 49b8fc2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import atexit
import errno
import gc
import os
import os.path as osp
import re
Expand Down Expand Up @@ -1950,6 +1951,10 @@ def show_toolbars(self):
self._update_show_toolbars_action()

# --- Other
def free_memory(self):
"""Free memory after event."""
gc.collect()

def plugin_focus_changed(self):
"""Focus has changed from one plugin to another"""
self.update_edit_menu()
Expand Down
14 changes: 13 additions & 1 deletion spyder/plugins/variableexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""Variable Explorer Plugin"""

# Third party imports
from qtpy.QtCore import Signal, Slot
from qtpy.QtCore import QTimer, Signal, Slot
from qtpy.QtWidgets import QGroupBox, QStackedWidget, QVBoxLayout

# Local imports
Expand Down Expand Up @@ -60,6 +60,8 @@ class VariableExplorer(SpyderPluginWidget):

CONF_SECTION = 'variable_explorer'
CONFIGWIDGET_CLASS = VariableExplorerConfigPage
INITIAL_FREE_MEMORY_TIME_TRIGGER = 60 * 1000 # ms
SECONDARY_FREE_MEMORY_TIME_TRIGGER = 180 * 1000 # ms
sig_option_changed = Signal(str, object)

def __init__(self, parent):
Expand Down Expand Up @@ -114,6 +116,15 @@ def change_option(self, option_name, new_value):
new_value = new_value[1:]
self.sig_option_changed.emit(option_name, new_value)

@Slot()
def free_memory(self):
"""Free memory signal."""
self.main.free_memory()
QTimer.singleShot(self.INITIAL_FREE_MEMORY_TIME_TRIGGER,
lambda: self.main.free_memory())
QTimer.singleShot(self.SECONDARY_FREE_MEMORY_TIME_TRIGGER,
lambda: self.main.free_memory())

# ----- Stack accesors ----------------------------------------------------
def set_current_widget(self, nsb):
self.stack.setCurrentWidget(nsb)
Expand Down Expand Up @@ -147,6 +158,7 @@ def add_shellwidget(self, shellwidget):
nsb.set_shellwidget(shellwidget)
nsb.setup(**self.get_settings())
nsb.sig_option_changed.connect(self.change_option)
nsb.sig_free_memory.connect(self.free_memory)
self.add_widget(nsb)
self.shellwidgets[shellwidget_id] = nsb
self.set_shellwidget_from_id(shellwidget_id)
Expand Down
7 changes: 5 additions & 2 deletions spyder/widgets/variableexplorer/collectionseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ def setData(self, index, value, role=Qt.EditRole):

class CollectionsDelegate(QItemDelegate):
"""CollectionsEditor Item Delegate"""
sig_free_memory = Signal()

def __init__(self, parent=None):
QItemDelegate.__init__(self, parent)
Expand Down Expand Up @@ -589,7 +590,7 @@ def editor_rejected(self, editor_id):

def free_memory(self):
"""Free memory after closing an editor."""
gc.collect()
self.sig_free_memory.emit()

def commitAndCloseEditor(self):
"""Overriding method commitAndCloseEditor"""
Expand Down Expand Up @@ -667,7 +668,8 @@ class BaseTableView(QTableView):
sig_option_changed = Signal(str, object)
sig_files_dropped = Signal(list)
redirect_stdio = Signal(bool)

sig_free_memory = Signal()

def __init__(self, parent):
QTableView.__init__(self, parent)
self.array_filename = None
Expand Down Expand Up @@ -1461,6 +1463,7 @@ def __init__(self, parent, data, minmax=False, shellwidget=None,
self.setModel(self.model)

self.delegate = RemoteCollectionsDelegate(self)
self.delegate.sig_free_memory.connect(self.sig_free_memory.emit)
self.setItemDelegate(self.delegate)

self.setup_table()
Expand Down
4 changes: 3 additions & 1 deletion spyder/widgets/variableexplorer/namespacebrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class NamespaceBrowser(QWidget):
"""Namespace browser (global variables explorer widget)"""
sig_option_changed = Signal(str, object)
sig_collapse = Signal()

sig_free_memory = Signal()

def __init__(self, parent, options_button=None, menu=None,
plugin_actions=None):
QWidget.__init__(self, parent)
Expand Down Expand Up @@ -118,6 +119,7 @@ def setup(self, check_all=None, exclude_private=None,

self.editor.sig_option_changed.connect(self.sig_option_changed.emit)
self.editor.sig_files_dropped.connect(self.import_data)
self.editor.sig_free_memory.connect(self.sig_free_memory.emit)

# Setup layout
blayout = QHBoxLayout()
Expand Down

0 comments on commit 49b8fc2

Please sign in to comment.