Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix async/bg tests cleanup
  • Loading branch information
T4rk1n committed Jul 8, 2025
commit 84af3ecdfa7dd965538a4a23227edab827a1e0e4
9 changes: 7 additions & 2 deletions dash/background_callback/managers/diskcache_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,14 @@ def terminate_job(self, job):
pass

try:
process.wait(1)
process.wait(2) # Increased timeout
except (psutil.TimeoutExpired, psutil.NoSuchProcess):
pass
# Force kill if still running
try:
process.kill()
process.wait(1)
except (psutil.TimeoutExpired, psutil.NoSuchProcess):
pass

def terminate_unhealthy_job(self, job):
import psutil # pylint: disable=import-outside-toplevel,import-error
Expand Down
21 changes: 20 additions & 1 deletion tests/async_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,26 @@ def setup_background_callback_app(manager_name, app_name):
for job in manager.running_jobs:
manager.terminate_job(job)

shutil.rmtree(cache_directory, ignore_errors=True)
# Wait for processes to actually terminate
import time

for _ in range(10): # Wait up to 5 seconds
if not manager.running_jobs:
break
time.sleep(0.5)

# Force cleanup with retry logic
import os

for _ in range(5):
try:
shutil.rmtree(cache_directory, ignore_errors=False)
break
except OSError:
time.sleep(0.5)
else:
# Final attempt with ignore_errors=True
shutil.rmtree(cache_directory, ignore_errors=True)
os.environ.pop("LONG_CALLBACK_MANAGER")
os.environ.pop("DISKCACHE_DIR")
from dash import page_registry
Expand Down
21 changes: 20 additions & 1 deletion tests/background_callback/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,26 @@ def setup_background_callback_app(manager_name, app_name):
for job in manager.running_jobs:
manager.terminate_job(job)

shutil.rmtree(cache_directory, ignore_errors=True)
# Wait for processes to actually terminate
import time

for _ in range(10): # Wait up to 5 seconds
if not manager.running_jobs:
break
time.sleep(0.5)

# Force cleanup with retry logic
import os

for _ in range(5):
try:
shutil.rmtree(cache_directory, ignore_errors=False)
break
except OSError:
time.sleep(0.5)
else:
# Final attempt with ignore_errors=True
shutil.rmtree(cache_directory, ignore_errors=True)
os.environ.pop("LONG_CALLBACK_MANAGER")
os.environ.pop("DISKCACHE_DIR")
from dash import page_registry
Expand Down
Loading