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

Fix python memory leak in table() #1724

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions python/perspective/perspective/table/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ def delete(self):
self._state_manager.remove_process(self._table.get_id())
self._table.unregister_gnode(self._gnode_id)
[cb() for cb in self._delete_callbacks]
self._table = None

def _update_callback(self, port_id):
"""After `process` completes internally, this method is called by the
Expand Down
43 changes: 43 additions & 0 deletions python/perspective/perspective/tests/table/test_leaks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
################################################################################
#
# Copyright (c) 2019, the Perspective Authors.
#
# This file is part of the Perspective library, distributed under the terms of
# the Apache License 2.0. The full license can be found in the LICENSE file.
#

from perspective.table import Table
import psutil
import os


class TestDelete(object):

# delete

def test_table_delete(self):
process = psutil.Process(os.getpid())
mem = process.memory_info().rss
for x in range(10000):
data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
tbl = Table(data)
tbl.delete()

mem2 = process.memory_info().rss

# assert 1 < (max2 / max) < 1.01
assert (mem2 - mem) < 2000000

def test_table_delete_with_view(self, sentinel):
data = [{"a": 1, "b": 2}, {"a": 3, "b": 4}]
tbl = Table(data)

process = psutil.Process(os.getpid())
mem = process.memory_info().rss
for x in range(10000):
view = tbl.view()
view.delete()

tbl.delete()
mem2 = process.memory_info().rss
assert (mem2 - mem) < 2000000
1 change: 1 addition & 0 deletions python/perspective/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"flake8>=3.7.8",
"flake8-black>=0.2.0",
"mock",
"psutil",
"pybind11>=2.4.0",
"pyarrow>=0.16.0",
"pytest>=4.3.0",
Expand Down
5 changes: 4 additions & 1 deletion scripts/test_python.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ const pytest_client_mode = (IS_DOCKER) => {
perspective/tests/client_mode"`;
} else {
return bash`cd ${python_path} && PYTHONMALLOC=debug ${PYTHON} -m pytest \
${VERBOSE ? "-vv --full-trace" : ""} --noconftest
${VERBOSE ? "-vv --full-trace" : ""} --noconftest
--disable-pytest-warnings
perspective/tests/client_mode`;
}
};
Expand All @@ -77,11 +78,13 @@ const pytest = (IS_DOCKER) => {
python/perspective && TZ=UTC PYTHONMALLOC=debug ${PYTHON} -m pytest \
${VERBOSE ? "-vv --full-trace" : ""} perspective \
--ignore=perspective/tests/client_mode \
--disable-pytest-warnings
--cov=perspective"`;
} else {
return bash`cd ${python_path} && PYTHONMALLOC=debug ${PYTHON} -m pytest \
${VERBOSE ? "-vv --full-trace" : ""} perspective \
--ignore=perspective/tests/client_mode \
--disable-pytest-warnings
${COVERAGE ? "--cov=perspective" : ""}`;
}
};
Expand Down