Problem caching Matplotlib Plots with Lock

We are trying to cach the rendering of matplotlib plots to improve the performance. The App has to be
accessible for multiple users at the same time, that is why RendererAgg.lock is used to fix matplotlib’s problem with multithreading. To prevent Streamlit from usings it’s hashing function we used “hash_funcs : lambda _: None”. The problem lies with the type of the lock and the hashing because even though hash_funcs is used there are errors.

AttributeError: '_thread.RLock' object has no attribute '__module__'
File "/Users/name/opt/anaconda3/envs/mne/lib/python3.8/site-packages/streamlit/", line 332, in _run_script
    exec(code, module.__dict__)
File "/Users/name/project/streamlit_mne_demo/", line 50, in <module>
    def plotEEG(eeg):
File "/Users/name/opt/anaconda3/envs/mne/lib/python3.8/site-packages/streamlit/", line 452, in <lambda>
    return lambda f: cache(
File "/Users/name/opt/anaconda3/envs/mne/lib/python3.8/site-packages/streamlit/", line 500, in cache
File "/Users/name/opt/anaconda3/envs/mne/lib/python3.8/site-packages/streamlit/", line 89, in update_hash
    ch = _CodeHasher(hash_funcs)
File "/Users/name/opt/anaconda3/envs/mne/lib/python3.8/site-packages/streamlit/", line 259, in __init__
    self._hash_funcs = {​​​​​​​
File "/Users/name/opt/anaconda3/envs/mne/lib/python3.8/site-packages/streamlit/", line 260, in <dictcomp>
    k if isinstance(k, str) else type_util.get_fqn(k): v
File "/Users/name/opt/anaconda3/envs/mne/lib/python3.8/site-packages/streamlit/", line 52, in get_fqn
    module = the_type.__module__