28 lines
881 B
Python
28 lines
881 B
Python
"""Isolated image renderer. Parent enforces wall time and kills this process."""
|
|
import os
|
|
import pickle
|
|
import sys
|
|
|
|
|
|
def main():
|
|
if sys.platform == 'linux':
|
|
import resource
|
|
limit = int(os.environ.get('RENDER_MEMORY_MB', '768')) * 1024 * 1024
|
|
resource.setrlimit(resource.RLIMIT_AS, (limit, limit))
|
|
from .worker import variants
|
|
from PIL import UnidentifiedImageError, Image
|
|
try:
|
|
data = sys.stdin.buffer.read(10485761)
|
|
if len(data) > 10485760:
|
|
raise ValueError('bytes limit')
|
|
result = variants(data, int(os.environ.get('MAX_IMAGE_PIXELS', '40000000')))
|
|
pickle.dump(result, sys.stdout.buffer)
|
|
except MemoryError:
|
|
sys.exit(21)
|
|
except (ValueError, OSError, SyntaxError, UnidentifiedImageError, Image.DecompressionBombError):
|
|
sys.exit(20)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|