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

Streamlit deletes sys.modules on reload #1430

Closed
MattSegal opened this issue May 9, 2020 · 2 comments
Closed

Streamlit deletes sys.modules on reload #1430

MattSegal opened this issue May 9, 2020 · 2 comments
Labels
priority:P3 type:bug Something isn't working

Comments

@MattSegal
Copy link

Summary

When you run streamlit and use the reload feature it will delete entries from the sys.modules dict, causing a KeyError.

Steps to reproduce

I can't seem to build a small reproducible example.
It's happening to me on https://github.com/monash-emu/AuTuMN for commit 1eab4e862ae9e9aa99d489e98f13a78383cb5834

The steps to reproduce are:

  • run streamlit
  • make file change in watched module
  • reload page with r
  • see error

video of reproduction: https://www.loom.com/share/74f242f7f2154708a8f54f6dff879101

Expected behavior:

No items are deleted from sys.modules on reload

Actual behavior:

Items are deleted from sys.modules on reload

Is this a regression?

Dunno

Debug info

  • Streamlit version: 0.58.0
  • Python version: 3.6.8
  • Using virtualenv
  • OS version: Ubuntu 18.04.4 LTS
  • Browser version: Chromium ???

Additional information

Prior discussion: https://discuss.streamlit.io/t/keyerror-warnings/2474/6

I believe this line of code is the cause:

del sys.modules[wm.module_name]

I was able to stop the error from happening by hacking in a fix to that module (see linked discussion)

@MattSegal MattSegal added type:bug Something isn't working status:needs-triage Has not been triaged by the Streamlit team labels May 9, 2020
@jrhone jrhone removed the status:needs-triage Has not been triaged by the Streamlit team label May 11, 2020
@batmanscode
Copy link

batmanscode commented Jul 12, 2020

I have the same (probably) issue. I get a KeyError as well whenever it reloads. I wish I saw the discussion before I reinstalled conda lol.

For me the problem line of code was results = model.predict(X_test) and this always worked fine on streamlit run but KeyError after a reload.

I'm using conda on windows, streamlit version: 0.62.1, python: 3.8.3

Fixed by adding:

import warnings
warnings.filterwarnings('ignore')

@jrieke
Copy link
Collaborator

jrieke commented Jul 21, 2023

Closing, since this seems to be covered in a reproducible way in #6404

@jrieke jrieke closed this as completed Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:P3 type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants