Status of st.callbacks.callbacks

Summary

Streamlit 1.20.0 contains a callbacks module that seems intended to provide timed (periodic/later/at) callbacks that play nicely with streamlit. The module fails to import, not finding StopException. Is this module under development?

Steps to reproduce

Code snippet:

from streamlit.callbacks.callbacks import periodic

To reproduce: just try the import into a Python environment that otherwise imports st modules fine.

Expected behavior:

If the module worked, the following should be possible, hopefully while keeping st responsive in between calls.

Code snippet:

from streamlit.callbacks.callbacks import periodic

em = st.empty()
sec_counter = -1
my_callback()
periodic(2.0, my_callback)

def my_callback(em):
    self.sec += 1
    em.write(f"~{self.sec} sec")

Actual behavior:

ImportError: cannot import name ‘StopException’ from ‘streamlit’ (…/site-packages/streamlit/init.py)

Debug info

  • Streamlit version: 1.20.0
  • Python version: 3.10.9
  • Using Conda
  • OS version: MacOS Monteray (10.4)
  • Browser version: n/a

Additional information

There are many timer solutions on the Web that attempt to create the timed callback functionality without sleep(), which would render st unresponsive. Having this apparently intended callback work would ensure it’s done properly in the context of st. Many uses, e.g. periodically checking a queue.

Hey @paepcke,

Sorry for the late reply on this! We do not have a callbacks.py in version 1.20 or the current version. Is it possible you’re using someone’s fork of Streamlit?

That doesn’t come with Streamlit, it is a third party package. It has a short development history that goes through the first half of 2021 and uses internal Streamlit APIs that have changed in recent versions. The latest release was uploaded to Pypi by a different person.

Good to know! Thanks for clarifying :slightly_smiling_face:

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.