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

Default to not caching sources in notebooks #1776

Merged
merged 1 commit into from
Jan 17, 2025
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Provide some latitude in vips multiframe detection ([#1770](../../pull/1770))
- Don't read multiplane ndpi files with openslide ([#1772](../../pull/1772))
- Harden sources based on more fuzz testing ([#1774](../../pull/1774))
- Default to not caching source in notebooks ([#1776](../../pull/1776))

### Bug Fixes

Expand Down
19 changes: 18 additions & 1 deletion large_image/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@
fallbackLogHandler.setLevel(logging.NOTSET)
fallbackLogger.addHandler(fallbackLogHandler)


def _in_notebook() -> bool:
"""
Try to detect if we are in an interactvie notebook.

:returns: True if we think we are in an interactive notebook.
"""
try:
shell = get_ipython().__class__.__name__ # type: ignore[name-defined]
# Jupyter
if shell == 'ZMQInteractiveShell':
return True
return False

Check warning on line 36 in large_image/config.py

View check run for this annotation

Codecov / codecov/patch

large_image/config.py#L35-L36

Added lines #L35 - L36 were not covered by tests
except NameError:
return False


ConfigValues = {
'logger': fallbackLogger,
'logprint': fallbackLogger,
Expand All @@ -40,7 +57,7 @@
# substantial performance penalties if sources are used multiple times, so
# should only be set in singular dynamic environments such as experimental
# notebooks.
'cache_sources': True,
'cache_sources': not _in_notebook(),

# Generally, these keys are the form of "cache_<cacheName>_<key>"

Expand Down
Loading