Utils
Common utilities used across the package.
log_time_taken ¶
A concise context manager to time code snippets and log the result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
process_name
|
str
|
Name of the process being timed. |
required |
Source code in fast_plate_ocr/core/utils.py
measure_time ¶
A context manager for measuring execution time (in milliseconds) within its code block.
Returns:
Type | Description |
---|---|
Iterator[Callable[[], float]]
|
A function that returns the elapsed time in milliseconds. |
Source code in fast_plate_ocr/core/utils.py
safe_write ¶
safe_write(
file: str | PathLike[str],
mode: str = "wb",
encoding: str | None = None,
**kwargs: Any,
) -> Iterator[IO]
Context manager for safe file writing.
Opens the specified file for writing and yields a file object. If an exception occurs during writing, the file is removed before raising the exception.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
str | PathLike[str]
|
Path to the file to write. |
required |
mode
|
str
|
File open mode (e.g. |
'wb'
|
encoding
|
str | None
|
Encoding to use (for text modes). Ignored in binary mode. |
None
|
**kwargs
|
Any
|
Additional arguments passed to |
{}
|
Returns:
Type | Description |
---|---|
Iterator[IO]
|
A writable file object. |