25 lines
760 B
Python
25 lines
760 B
Python
"""Одноразовый Linux-процесс декодирования с пределами памяти и CPU"""
|
|
|
|
from pathlib import Path
|
|
import resource
|
|
import sys
|
|
|
|
from app.domain.image_validation import decode_image
|
|
from app.errors.exceptions import IMAGE_WORKER_ERRORS, image_worker_error_code
|
|
|
|
|
|
def main() -> int:
|
|
resource.setrlimit(resource.RLIMIT_AS, (512 * 1024 * 1024, 512 * 1024 * 1024))
|
|
resource.setrlimit(resource.RLIMIT_CPU, (10, 10))
|
|
path, content_type, maximum = sys.argv[1:]
|
|
status = 0
|
|
try:
|
|
decode_image(Path(path), content_type, int(maximum))
|
|
except IMAGE_WORKER_ERRORS as error:
|
|
status = image_worker_error_code(error)
|
|
return status
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|