Skip to content

Changing deeply imported python modules does not hot-reload properly #366

@treuille

Description

@treuille

Summary

If a python file a.py imports a module b which imports c, then changnes to c don't hot-reload properly to update a.

Steps to reproduce

In essence we will setup an import chain a -> b -> c where

  • a prints b.x and b.y
  • b.x is defined directly in b
  • b.y is defined as c.foo

Thus a depends on b directly and c "deeply" (step 1). Updating the direct import (step 2) works properly, but updating the deep import (step 3) fails. As a sanity check, restarting the server (step 4) displays the correct output.

Step 1: Setup the import chain (THIS WORKS)

We will setup the import chain a -> b -> c by defining these three files:

a.py:

import streamlit as st
import b

st.write('b.x:', b.x, 'b.y:', b.y)

b.py:

import c

x = 41
y = c.foo

c.py:

foo = 33

When we streamlit run a.py we see the correct output:

image

Step 2: Update the imported module b (THIS WORKS)

Without closing the server created in step 1, update b.py as follows:

import c

x = 42
y = c.foo

This change is hot-reloaded and again we see the correct output:

image

Step 3: Update the deeply imported module c (THIS DOESN'T WORK!!)

Again without closing the server, update c.py as follows:

foo = 34

This change is hot-reloaded but we do not see the correct output:

image

Step 4: Demonstrate the correct ouput by killing and restarting the server.

Kill the server and run it again (streamlit run a.py) and you will see the correct output:

image

Behavior

Actual behavior

Described above.

Expected behavior

Changing a deeply imported module (c) should correctly update everything.

In other words, we should see the step 4 output after step 3.

Is this a regression?

Probably not.

Debug info

$ streamlit version && python --version && pyenv --version && sw_vers && "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --version
Streamlit, version 0.47.4
Python 3.6.3
pyenv 1.2.3
ProductName:    Mac OS X
ProductVersion: 10.14.6
BuildVersion:   18G103
Google Chrome 77.0.3865.90 

Additional information

This is the second of two bugs based on this awesome-streamlit issue. The first bug is this.

Metadata

Metadata

Assignees

Labels

type:bugSomething isn't working as expected

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions