Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lukasmasuch
Copy link
Collaborator

@lukasmasuch lukasmasuch commented Jul 2, 2025

Describe your changes

Applies a couple of improvements to the file watcher to make it more error-resistant.

GitHub Issue Link (if applicable)

Testing Plan

  • Updated tests.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@snyk-io
Copy link
Contributor

snyk-io bot commented Jul 2, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@github-actions
Copy link
Contributor

github-actions bot commented Jul 2, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-11841/streamlit-1.46.1-py3-none-any.whl
🕹️ Preview app pr-11841.streamlit.app (☁️ Deploy here if not accessible)

@lukasmasuch lukasmasuch added security-assessment-completed Security assessment has been completed for PR change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Jul 2, 2025
@lukasmasuch lukasmasuch requested a review from Copilot July 3, 2025 01:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the file-watching logic by normalizing paths with os.path.realpath, improving error handling in watcher registration and path-change events, and updating tests to accommodate full path comparisons.

  • Switched from os.path.abspath to os.path.realpath across watcher implementations for consistent path normalization.
  • Wrapped watcher scheduling and MD5 computation in broader exception handling with logged warnings.
  • Adjusted tests to match substrings in full paths rather than exact filenames.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/tests/streamlit/watcher/local_sources_watcher_test.py Updated assertions to use substring checks for full paths.
lib/streamlit/watcher/util.py Added a blank line before retry loop in _do_with_retries.
lib/streamlit/watcher/local_sources_watcher.py Replaced abspath with realpath and improved exception logging.
lib/streamlit/watcher/event_based_path_watcher.py Switched to realpath, ignored editor backup files, and added exception handling in scheduling and MD5 calc.
Comments suppressed due to low confidence (1)

@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2025

📉 Python coverage change detected

The Python unit test coverage has decreased by 0.0508%

  • Current PR: 92.2281% (18168 statements, 1412 missed)
  • Latest develop: 92.2789% (18145 statements, 1401 missed)

💡 Consider adding more unit tests to maintain or improve coverage.

Coverage by files
Name Stmts Miss Cover
streamlit/__init__.py 139 0 100%
streamlit/__main__.py 3 3 0%
streamlit/auth_util.py 100 25 75%
streamlit/cli_util.py 39 6 85%
streamlit/column_config.py 3 0 100%
streamlit/commands/__init__.py 0 0 100%
streamlit/commands/echo.py 54 11 80%
streamlit/commands/execution_control.py 59 10 83%
streamlit/commands/experimental_query_params.py 40 2 95%
streamlit/commands/logo.py 40 6 85%
streamlit/commands/navigation.py 107 2 98%
streamlit/commands/page_config.py 101 4 96%
streamlit/components/__init__.py 0 0 100%
streamlit/components/lib/__init__.py 0 0 100%
streamlit/components/lib/local_component_registry.py 35 2 94%
streamlit/components/types/__init__.py 0 0 100%
streamlit/components/types/base_component_registry.py 14 0 100%
streamlit/components/types/base_custom_component.py 49 6 88%
streamlit/components/v1/__init__.py 5 0 100%
streamlit/components/v1/component_arrow.py 33 8 76%
streamlit/components/v1/component_registry.py 41 3 93%
streamlit/components/v1/components.py 4 4 0%
streamlit/components/v1/custom_component.py 92 7 92%
streamlit/config.py 336 13 96%
streamlit/config_option.py 79 3 96%
streamlit/config_util.py 81 1 99%
streamlit/connections/__init__.py 6 0 100%
streamlit/connections/base_connection.py 45 0 100%
streamlit/connections/snowflake_connection.py 60 13 78%
streamlit/connections/snowpark_connection.py 44 3 93%
streamlit/connections/sql_connection.py 55 6 89%
streamlit/connections/util.py 33 0 100%
streamlit/cursor.py 82 2 98%
streamlit/dataframe_util.py 506 45 91%
streamlit/delta_generator.py 203 6 97%
streamlit/delta_generator_singletons.py 76 8 89%
streamlit/deprecation_util.py 57 4 93%
streamlit/development.py 1 0 100%
streamlit/elements/__init__.py 0 0 100%
streamlit/elements/alert.py 60 0 100%
streamlit/elements/arrow.py 170 12 93%
streamlit/elements/balloons.py 10 0 100%
streamlit/elements/bokeh_chart.py 25 0 100%
streamlit/elements/code.py 20 1 95%
streamlit/elements/deck_gl_json_chart.py 97 6 94%
streamlit/elements/dialog_decorator.py 58 2 97%
streamlit/elements/doc_string.py 227 9 96%
streamlit/elements/empty.py 16 4 75%
streamlit/elements/exception.py 101 10 90%
streamlit/elements/form.py 51 2 96%
streamlit/elements/graphviz_chart.py 29 1 97%
streamlit/elements/heading.py 57 0 100%
streamlit/elements/html.py 48 0 100%
streamlit/elements/iframe.py 32 1 97%
streamlit/elements/image.py 32 1 97%
streamlit/elements/json.py 39 2 95%
streamlit/elements/layouts.py 125 2 98%
streamlit/elements/lib/__init__.py 0 0 100%
streamlit/elements/lib/built_in_chart_utils.py 359 27 92%
streamlit/elements/lib/color_util.py 102 4 96%
streamlit/elements/lib/column_config_utils.py 169 1 99%
streamlit/elements/lib/column_types.py 132 1 99%
streamlit/elements/lib/dialog.py 54 2 96%
streamlit/elements/lib/dicttools.py 39 2 95%
streamlit/elements/lib/file_uploader_utils.py 22 0 100%
streamlit/elements/lib/form_utils.py 26 0 100%
streamlit/elements/lib/image_utils.py 179 25 86%
streamlit/elements/lib/js_number.py 28 3 89%
streamlit/elements/lib/layout_utils.py 53 0 100%
streamlit/elements/lib/mutable_status_container.py 73 4 95%
streamlit/elements/lib/options_selector_utils.py 97 0 100%
streamlit/elements/lib/pandas_styler_utils.py 71 1 99%
streamlit/elements/lib/policies.py 56 1 98%
streamlit/elements/lib/streamlit_plotly_theme.py 49 0 100%
streamlit/elements/lib/subtitle_utils.py 76 13 83%
streamlit/elements/lib/utils.py 77 5 94%
streamlit/elements/map.py 106 1 99%
streamlit/elements/markdown.py 63 2 97%
streamlit/elements/media.py 183 8 96%
streamlit/elements/metric.py 83 5 94%
streamlit/elements/plotly_chart.py 95 3 97%
streamlit/elements/progress.py 37 0 100%
streamlit/elements/pyplot.py 34 2 94%
streamlit/elements/snow.py 10 0 100%
streamlit/elements/spinner.py 34 0 100%
streamlit/elements/text.py 16 0 100%
streamlit/elements/toast.py 17 0 100%
streamlit/elements/vega_charts.py 208 3 99%
streamlit/elements/widgets/__init__.py 0 0 100%
streamlit/elements/widgets/audio_input.py 63 11 83%
streamlit/elements/widgets/button.py 198 45 77%
streamlit/elements/widgets/button_group.py 172 0 100%
streamlit/elements/widgets/camera_input.py 63 10 84%
streamlit/elements/widgets/chat.py 170 42 75%
streamlit/elements/widgets/checkbox.py 52 0 100%
streamlit/elements/widgets/color_picker.py 56 3 95%
streamlit/elements/widgets/data_editor.py 232 13 94%
streamlit/elements/widgets/file_uploader.py 108 19 82%
streamlit/elements/widgets/multiselect.py 108 4 96%
streamlit/elements/widgets/number_input.py 154 6 96%
streamlit/elements/widgets/radio.py 88 6 93%
streamlit/elements/widgets/select_slider.py 101 1 99%
streamlit/elements/widgets/selectbox.py 102 2 98%
streamlit/elements/widgets/slider.py 248 9 96%
streamlit/elements/widgets/text_widgets.py 131 7 95%
streamlit/elements/widgets/time_widgets.py 255 17 93%
streamlit/elements/write.py 170 30 82%
streamlit/emojis.py 4 0 100%
streamlit/env_util.py 21 3 86%
streamlit/error_util.py 33 2 94%
streamlit/errors.py 153 28 82%
streamlit/external/__init__.py 0 0 100%
streamlit/external/langchain/__init__.py 2 0 100%
streamlit/external/langchain/streamlit_callback_handler.py 141 82 42%
streamlit/file_util.py 84 8 90%
streamlit/git_util.py 100 63 37%
streamlit/logger.py 54 0 100%
streamlit/material_icon_names.py 1 0 100%
streamlit/navigation/__init__.py 0 0 100%
streamlit/navigation/page.py 78 2 97%
streamlit/net_util.py 55 3 95%
streamlit/platform.py 10 1 90%
streamlit/runtime/__init__.py 8 0 100%
streamlit/runtime/app_session.py 410 74 82%
streamlit/runtime/caching/__init__.py 19 0 100%
streamlit/runtime/caching/cache_data_api.py 170 3 98%
streamlit/runtime/caching/cache_errors.py 46 1 98%
streamlit/runtime/caching/cache_resource_api.py 127 0 100%
streamlit/runtime/caching/cache_type.py 11 1 91%
streamlit/runtime/caching/cache_utils.py 170 9 95%
streamlit/runtime/caching/cached_message_replay.py 110 2 98%
streamlit/runtime/caching/hashing.py 301 22 93%
streamlit/runtime/caching/legacy_cache_api.py 13 0 100%
streamlit/runtime/caching/storage/__init__.py 2 0 100%
streamlit/runtime/caching/storage/cache_storage_protocol.py 31 2 94%
streamlit/runtime/caching/storage/dummy_cache_storage.py 21 0 100%
streamlit/runtime/caching/storage/in_memory_cache_storage_wrapper.py 60 0 100%
streamlit/runtime/caching/storage/local_disk_cache_storage.py 86 4 95%
streamlit/runtime/connection_factory.py 85 9 89%
streamlit/runtime/context.py 140 41 71%
streamlit/runtime/context_util.py 18 0 100%
streamlit/runtime/credentials.py 142 3 98%
streamlit/runtime/forward_msg_cache.py 23 2 91%
streamlit/runtime/forward_msg_queue.py 63 4 94%
streamlit/runtime/fragment.py 124 2 98%
streamlit/runtime/media_file_manager.py 69 7 90%
streamlit/runtime/media_file_storage.py 15 0 100%
streamlit/runtime/memory_media_file_storage.py 68 0 100%
streamlit/runtime/memory_session_storage.py 15 0 100%
streamlit/runtime/memory_uploaded_file_manager.py 41 1 98%
streamlit/runtime/metrics_util.py 194 12 94%
streamlit/runtime/pages_manager.py 59 2 97%
streamlit/runtime/runtime.py 235 16 93%
streamlit/runtime/runtime_util.py 30 1 97%
streamlit/runtime/script_data.py 16 0 100%
streamlit/runtime/scriptrunner/__init__.py 5 0 100%
streamlit/runtime/scriptrunner/exec_code.py 49 5 90%
streamlit/runtime/scriptrunner/magic.py 83 1 99%
streamlit/runtime/scriptrunner/magic_funcs.py 10 1 90%
streamlit/runtime/scriptrunner/script_cache.py 27 0 100%
streamlit/runtime/scriptrunner/script_runner.py 230 27 88%
streamlit/runtime/scriptrunner_utils/__init__.py 0 0 100%
streamlit/runtime/scriptrunner_utils/exceptions.py 11 1 91%
streamlit/runtime/scriptrunner_utils/script_requests.py 106 5 95%
streamlit/runtime/scriptrunner_utils/script_run_context.py 136 2 99%
streamlit/runtime/secrets.py 243 25 90%
streamlit/runtime/session_manager.py 60 1 98%
streamlit/runtime/state/__init__.py 7 0 100%
streamlit/runtime/state/common.py 49 2 96%
streamlit/runtime/state/query_params.py 109 3 97%
streamlit/runtime/state/query_params_proxy.py 81 0 100%
streamlit/runtime/state/safe_session_state.py 73 14 81%
streamlit/runtime/state/session_state.py 359 13 96%
streamlit/runtime/state/session_state_proxy.py 62 8 87%
streamlit/runtime/state/widgets.py 12 1 92%
streamlit/runtime/stats.py 42 0 100%
streamlit/runtime/uploaded_file_manager.py 39 3 92%
streamlit/runtime/websocket_session_manager.py 62 0 100%
streamlit/source_util.py 36 1 97%
streamlit/string_util.py 74 2 97%
streamlit/temporary_directory.py 16 1 94%
streamlit/testing/__init__.py 0 0 100%
streamlit/testing/v1/__init__.py 2 0 100%
streamlit/testing/v1/app_test.py 239 6 97%
streamlit/testing/v1/element_tree.py 1328 85 94%
streamlit/testing/v1/local_script_runner.py 71 2 97%
streamlit/testing/v1/util.py 17 0 100%
streamlit/time_util.py 32 1 97%
streamlit/type_util.py 143 9 94%
streamlit/url_util.py 40 5 88%
streamlit/user_info.py 87 8 91%
streamlit/util.py 35 1 97%
streamlit/version.py 3 0 100%
streamlit/watcher/__init__.py 3 0 100%
streamlit/watcher/event_based_path_watcher.py 174 24 86%
streamlit/watcher/folder_black_list.py 14 1 93%
streamlit/watcher/local_sources_watcher.py 127 9 93%
streamlit/watcher/path_watcher.py 43 3 93%
streamlit/watcher/polling_path_watcher.py 54 2 96%
streamlit/watcher/util.py 49 1 98%
streamlit/web/__init__.py 0 0 100%
streamlit/web/bootstrap.py 145 19 87%
streamlit/web/cache_storage_manager_config.py 5 0 100%
streamlit/web/cli.py 176 17 90%
streamlit/web/server/__init__.py 5 0 100%
streamlit/web/server/app_static_file_handler.py 29 3 90%
streamlit/web/server/authlib_tornado_integration.py 18 1 94%
streamlit/web/server/browser_websocket_handler.py 109 27 75%
streamlit/web/server/component_request_handler.py 64 6 91%
streamlit/web/server/media_file_handler.py 65 9 86%
streamlit/web/server/oauth_authlib_routes.py 118 18 85%
streamlit/web/server/oidc_mixin.py 44 0 100%
streamlit/web/server/routes.py 87 7 92%
streamlit/web/server/server.py 173 9 95%
streamlit/web/server/server_util.py 67 5 93%
streamlit/web/server/stats_request_handler.py 53 4 92%
streamlit/web/server/upload_file_request_handler.py 53 9 83%
streamlit/web/server/websocket_headers.py 19 1 95%
TOTAL 18168 1412 92%

📊 View detailed coverage comparison

@lukasmasuch lukasmasuch changed the title [WIP] Improve file watcher Make file watcher more error-resistant Jul 3, 2025
@lukasmasuch lukasmasuch marked this pull request as ready for review July 3, 2025 13:35
Copy link
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lukasmasuch lukasmasuch merged commit 9a1778b into develop Jul 4, 2025
37 checks passed
@lukasmasuch lukasmasuch deleted the improve-file-watcher branch July 4, 2025 10:14
lukasmasuch added a commit that referenced this pull request Jul 9, 2025
## Describe your changes

Follow-up to #11841 to
improve the exception handling. The changes in
#11841 can create some
confusing logs and catch unrelated exceptions (e.g. runtime errors when
the runtime shuts down).

## Testing Plan

- This is mainly about logging and doesn't have any functional impact.

---

**Contribution License Agreement**

By submitting this pull request you agree that all contributions to this
project are made under the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

3 participants