Skip to content

Commit

Permalink
Default to not caching source in notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Jan 17, 2025
1 parent 96673e4 commit d805bdf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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

0 comments on commit d805bdf

Please sign in to comment.