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

[gui] [ipython] Add GUI.__del__ to close on variable dereference #1869

Merged
merged 7 commits into from
Sep 26, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion python/taichi/lang/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
_env_enable_pybuf = os.environ.get('TI_ENABLE_PYBUF', '1')
if not _env_enable_pybuf or int(_env_enable_pybuf):
# When using in Jupyter / IDLE, the sys.stdout will be their wrapped ones.
pybuf_enabled = type(sys.stdout).__name__ != 'TextIOWrapper'
# While sys.__stdout__ should always be the raw console stdout.
pybuf_enabled = sys.stdout != sys.__stdout__
archibate marked this conversation as resolved.
Show resolved Hide resolved

from .core import taichi_lang_core
taichi_lang_core.toggle_python_print_buffer(pybuf_enabled)
Expand Down
3 changes: 3 additions & 0 deletions python/taichi/misc/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def __enter__(self):
def __exit__(self, type, val, tb):
self.close()

def __del__(self):
self.close()

def close(self):
self.core = None # dereference to call GUI::~GUI()

Expand Down
1 change: 1 addition & 0 deletions taichi/gui/win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ GUI::~GUI() {
if (show_gui) {
std::free(data);
DeleteDC(src);
DestroyWindow(hwnd);
gui_from_hwnd.erase(hwnd);
}
}
Expand Down