dash_duo.server.stop() kills threads that it doesn't own - ones that were created after its inception
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 24.4k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 13
Description
Describe your context
dash 2.14.1
dash-core-components 2.0.0
dash-html-components 2.0.0
dash-table 5.0.0
dash-testing-stub 0.0.2
Describe the bug
KillerThread kills all threads that were created since the server's inception. This appears to be intended, but it shouldn't be. Dash should only modify threads that it has created.
Execute pytest -sv on the following example:
import dash
from dash import html
import threading
import time
def some_function_on_a_different_thread():
try:
print("starting long work")
time.sleep(5)
print("ending long work")
except SystemExit:
print("Thread received SystemExit.")
def test_some_function(dash_duo):
app = dash.Dash(__name__)
app.layout = html.Div(id="nully-wrapper", children=0)
dash_duo.start_server(app)
time.sleep(1)
# This function could interact with the webpage, or do some other important work
# in the background.
my_thread = threading.Thread(target=some_function_on_a_different_thread)
my_thread.start()
dash_duo.server.stop()
This is a rather contrived example, but I have pytest fixtures that spin up services that must last between tests, all of whom may or may not create their own threads throughout the session's lifetime.
Expected behavior
Test should hang for ~5 seconds, and then "ending long work" is printed.
Actual behavior
Test lasts ~1 second, and "Thread received SystemExit." is printed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with dash/testing/application_runners.py around line 122 and reproduce the issue by running the provided example with pytest -sv. Trace how dash_duo.server.stop() selects threads and compare that with the thread created after server startup. Done means the unrelated thread is not stopped, the test lasts about five seconds, and "ending long work" is printed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100