mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
Address final code review nitpicks: improve code organization
Co-authored-by: denizsafak <39929354+denizsafak@users.noreply.github.com>
This commit is contained in:
co-authored by
denizsafak
parent
5cca6235e1
commit
711858ce2c
@@ -28,6 +28,9 @@ import threading # for efficient waiting
|
|||||||
import subprocess
|
import subprocess
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
|
# Configuration constants
|
||||||
|
_USER_RESPONSE_TIMEOUT = 0.1 # Timeout in seconds for checking user response/cancellation
|
||||||
|
|
||||||
# Pre-compile frequently used regex patterns for better performance
|
# Pre-compile frequently used regex patterns for better performance
|
||||||
_METADATA_TAG_PATTERN = re.compile(r"<<METADATA_[^:]+:[^>]*>>")
|
_METADATA_TAG_PATTERN = re.compile(r"<<METADATA_[^:]+:[^>]*>>")
|
||||||
_CHAPTER_MARKER_PATTERN = re.compile(r"<<CHAPTER_MARKER:[^>]*>>")
|
_CHAPTER_MARKER_PATTERN = re.compile(r"<<CHAPTER_MARKER:[^>]*>>")
|
||||||
@@ -875,10 +878,11 @@ class ConversionThread(QThread):
|
|||||||
# Signal to ask user (-1 indicates timestamp detection)
|
# Signal to ask user (-1 indicates timestamp detection)
|
||||||
self.chapters_detected.emit(-1)
|
self.chapters_detected.emit(-1)
|
||||||
# Wait for user response using event with timeout for responsive cancellation
|
# Wait for user response using event with timeout for responsive cancellation
|
||||||
while not self._timestamp_response_event.wait(timeout=0.1):
|
while not self._timestamp_response_event.wait(timeout=_USER_RESPONSE_TIMEOUT):
|
||||||
if self.cancel_requested:
|
if self.cancel_requested:
|
||||||
self.conversion_finished.emit("Cancelled", None)
|
self.conversion_finished.emit("Cancelled", None)
|
||||||
return
|
return
|
||||||
|
# Check cancellation one more time after event is set
|
||||||
if self.cancel_requested:
|
if self.cancel_requested:
|
||||||
self.conversion_finished.emit("Cancelled", None)
|
self.conversion_finished.emit("Cancelled", None)
|
||||||
return
|
return
|
||||||
|
|||||||
+1
-1
@@ -9,6 +9,7 @@ are working correctly and don't introduce regressions.
|
|||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
def test_regex_precompilation_performance():
|
def test_regex_precompilation_performance():
|
||||||
@@ -213,7 +214,6 @@ def main():
|
|||||||
return 1
|
return 1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"\n❌ Unexpected error: {e}")
|
print(f"\n❌ Unexpected error: {e}")
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user