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

Lazily import matplotlib #314

Merged
merged 1 commit into from
Aug 26, 2021
Merged

Lazily import matplotlib #314

merged 1 commit into from
Aug 26, 2021

Conversation

bemoody
Copy link
Collaborator

@bemoody bemoody commented Jul 19, 2021

Importing the 'matplotlib' library does all kinds of crazy stuff (such as crashing, sometimes, depending on what other packages are/aren't installed and whether or not DISPLAY is set), and makes startup significantly slower. If your program is not actually doing anything involving plotting, this unpredictability and slowness is a nuisance.

Thus, only import the library in functions that use it.

A few functions (wfdb.plot_items, wfdb.plot.plot.create_figure,
wfdb.processing.Comparitor.plot) can be used to display graphical
plots using matplotlib.

When the matplotlib module is imported, it does a lot of non-trivial
initialization, which is slow and will sometimes fail in unpredictable
ways (depending on the environment and depending on whether other
nominally-optional dependencies, such as Tk, are installed.)

It's rather absurd for the behavior of importing wfdb to be dependent
on existence or non-existence of a window system, so only import
matplotlib in the few functions that actually use it.
@bemoody
Copy link
Collaborator Author

bemoody commented Aug 26, 2021

Merging this as I've heard no objections.

@bemoody bemoody merged commit 916ec90 into master Aug 26, 2021
@bemoody bemoody deleted the lazy-matplotlib branch August 26, 2021 19:15
@tompollard tompollard mentioned this pull request Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant