srush / streambook

Live Python Notebooks with any Editor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Browser update not triggered

jbcdnr opened this issue · comments

Hello,

Thanks a lot for putting these tools together, looks like a fun workflow!

I have the following problem on Mac: the streamlit file watcher does not seem to trigger the rerun. It's not exactly the same as #2 as script.streambook.py is updated when I save script.py. It's only the streamlit watcher that does not trigger. The exception below seems to indicate that a single observer can be set per directory in a single program and the one from streambook clashes with the one from streamlit.

Streambook Daemon

Watching directory for changes:

 /Users/user/Desktop/test

View Command
streamlit run  --server.runOnSave true /Users/user/Desktop/test/lipschitz.streambook.py

Notebook Execution Command
jupytext --to notebook --execute /Users/user/Desktop/test/lipschitz.notebook.py
Regenerating from /Users/user/Desktop/test/lipschitz.py...

Starting Streamlit
[...]
2021-04-22 17:17:18.561 INFO    fsevents: queue_event <FileModifiedEvent: event_type=modified, src_path='/Users/user/Desktop/test/lipschitz.notebook.py', is_directory=False>
2021-04-22 17:17:18.662 An update to the [server] config option section was detected. To have these changes be reflected, please restart streamlit.
2021-04-22 17:17:19.040 queue_event <DirModifiedEvent: event_type=modified, src_path='/Users/user/Desktop/test', is_directory=True>
2021-04-22 17:17:19.941 Unhandled exception in FSEventsEmitter
Traceback (most recent call last):
  File "/Users/user/anaconda3/lib/python3.7/site-packages/watchdog/observers/fsevents.py", line 283, in run
    _fsevents.add_watch(self, self.watch, callback, self.pathnames)
RuntimeError: Cannot add watch <ObservedWatch: path=/Users/user/Desktop/test, is_recursive=False> - it is already scheduled

For now, I have found a workaround by commenting the launch of streamlit here and starting it with the command line. Do you have an idea for a cleaner solution?

I see. Why don't we temporarily add a command-line option that watches for changes, but doesn't launch streamlit. Launching it in one program is a bit of a hack and might not work well on mac.

Thanks for your quick reply. Is there a reason for not launching streamlit with a subprocess?

import subprocess
subprocess.run(["streamlit", "run", "--server.runOnSave", "true", stream_file], capture_output=True)

It seems to solve my problem but I might be overlooking some disadvantages.

No that seems better if it works . I was following their docs.

Want to send a PR?

(Either way we should also have a --nostreamlit opt. Maybe also a --port opt, or --stopts that gets passed through.)