Spaces:
Runtime error
Runtime error
Download src/ui/utils/threading_utils.py from Ansemin101/Markit_v2: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/Ansemin101/Markit_v2/resolve/main/src/ui/utils/threading_utils.py
- Command line
-
hf download hf://spaces/Ansemin101/Markit_v2/src/ui/utils/threading_utils.py
-
curl -L -o threading_utils.py https://huggingface.co/spaces/Ansemin101/Markit_v2/resolve/main/src/ui/utils/threading_utils.py
1.03 kB
| """Threading utilities for UI components.""" | |
| import threading | |
| import time | |
| import logging | |
| from src.core.converter import is_conversion_in_progress | |
| from src.core.logging_config import get_logger | |
| logger = get_logger(__name__) | |
| # Global variable to track cancellation state | |
| conversion_cancelled = threading.Event() | |
| def monitor_cancellation(): | |
| """Background thread to monitor cancellation and update UI if needed""" | |
| logger.info("Starting cancellation monitor thread") | |
| while is_conversion_in_progress(): | |
| if conversion_cancelled.is_set(): | |
| logger.info("Cancellation detected by monitor thread") | |
| time.sleep(0.1) # Check every 100ms | |
| logger.info("Cancellation monitor thread ending") | |
| def get_cancellation_event(): | |
| """Get the global cancellation event.""" | |
| return conversion_cancelled | |
| def reset_cancellation(): | |
| """Reset the cancellation event.""" | |
| conversion_cancelled.clear() | |
| def set_cancellation(): | |
| """Set the cancellation event.""" | |
| conversion_cancelled.set() |