Skip to content

Conversation

@DeltaGa
Copy link
Contributor

@DeltaGa DeltaGa commented Jan 11, 2025

MINOR CHANGES (1)

  • Updated the logic of starting the server to prevent calling asyncio.run() from a running event loop.

Describe your changes

Refactored the server startup logic to ensure compatibility with both existing and new event loops. This prevents the RuntimeError encountered when asyncio.run() is called from a running event loop on Python 3.10.16,

GitHub Issue Link (if applicable)

No GitHub issue link available.

Testing Plan

I would be grateful if someone could test the code using the existing tests. The changes have been verified through manual testing.

  • Explanation of why no additional tests are needed:
    The refactored code has been manually tested and works as expected.

  • Unit Tests (JS and/or Python):
    [@raethlein]: Added a Python unit test to ensure that bootstrap.run works with and without an existing asyncio eventloop.

  • E2E Tests:
    None.

  • Any manual testing needed?
    Manual testing was performed to ensure the server starts correctly in both new and existing event loops.


Contribution License Agreement

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

MINOR CHANGES
- updated the logic of starting the server to prevent calling asyncio.run() from a running event loop.
@raethlein
Copy link
Collaborator

@DeltaGa Thanks for the PR! This looks great 🙂 We might want to add a test to bootstrap_test.py to make sure the behavior is not accidentally changed in the future. I will look into this this week 👍

@raethlein raethlein added security-assessment-completed Security assessment has been completed for PR change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Jan 15, 2025
Copy link
Collaborator

@raethlein raethlein left a comment

Choose a reason for hiding this comment

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

I applied formatting and added a unit test ✅ Looks good to me now, thanks a lot for your work!

Copy link
Collaborator

@lukasmasuch lukasmasuch 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 changed the title Update bootstrap.py - RuntimeError FIX Allow reusing existing event loop for server Jan 16, 2025
@raethlein raethlein merged commit 2928ca9 into streamlit:develop Jan 16, 2025
32 checks passed
edegp pushed a commit to edegp/streamlit that referenced this pull request Jan 19, 2025
## MINOR CHANGES (1)
- Updated the logic of starting the server to prevent calling
`asyncio.run()` from a running event loop.

## Describe your changes
Refactored the server startup logic to ensure compatibility with both
existing and new event loops. This prevents the `RuntimeError`
encountered when `asyncio.run()` is called from a running event loop on
Python 3.10.16,

## GitHub Issue Link (if applicable)
No GitHub issue link available.

## Testing Plan
I would be grateful if someone could test the code using the existing
tests. The changes have been verified through manual testing.

- Explanation of why no additional tests are needed:
  The refactored code has been manually tested and works as expected.

- Unit Tests (JS and/or Python):
[@raethlein]: Added a Python unit test to ensure that `bootstrap.run`
works with and without an existing asyncio eventloop.

- E2E Tests:
  _None._

- Any manual testing needed?
Manual testing was performed to ensure the server starts correctly in
both new and existing event loops.

---


**Contribution License Agreement**

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

---------

Co-authored-by: raethlein <[email protected]>
mayagbarnes added a commit that referenced this pull request Feb 20, 2025
`asyncio.get_running_loop()` throws a `RuntimeError: There is no current event loop in thread 'MainThread'` when this is no current event loop.
Resolves issue introduced in PR #10164. Closes #10452
sfc-gh-mbarnes pushed a commit that referenced this pull request Feb 20, 2025
`asyncio.get_running_loop()` throws a `RuntimeError: There is no current event loop in thread 'MainThread'` when this is no current event loop.
Resolves issue introduced in PR #10164. Closes #10452
sfc-gh-mbarnes pushed a commit that referenced this pull request Feb 20, 2025
`asyncio.get_running_loop()` throws a `RuntimeError: There is no current event loop in thread 'MainThread'` when this is no current event loop.
Resolves issue introduced in PR #10164. Closes #10452
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants