mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 02:16:19 +03:00
d50445ff30
Similar to the recent adoption of Black. isort is a Python utility to sort imports alphabetically and automatically separate into sections. By using isort, contributors can quickly and automatically conform to the projects style without thinking. Just let the tool do it. Uses the configuration recommended by the Black to avoid conflicts of style. Rewrite TestImageQt.test_deprecated to no rely on import order.
60 lines
1.0 KiB
Python
60 lines
1.0 KiB
Python
from __future__ import print_function
|
|
|
|
import io
|
|
import queue
|
|
import sys
|
|
import threading
|
|
import time
|
|
|
|
from PIL import Image
|
|
|
|
test_format = sys.argv[1] if len(sys.argv) > 1 else "PNG"
|
|
|
|
im = Image.open("Tests/images/hopper.ppm")
|
|
im.load()
|
|
|
|
queue = queue.Queue()
|
|
|
|
result = []
|
|
|
|
|
|
class Worker(threading.Thread):
|
|
def run(self):
|
|
while True:
|
|
im = queue.get()
|
|
if im is None:
|
|
queue.task_done()
|
|
sys.stdout.write("x")
|
|
break
|
|
f = io.BytesIO()
|
|
im.save(f, test_format, optimize=1)
|
|
data = f.getvalue()
|
|
result.append(len(data))
|
|
im = Image.open(io.BytesIO(data))
|
|
im.load()
|
|
sys.stdout.write(".")
|
|
queue.task_done()
|
|
|
|
|
|
t0 = time.time()
|
|
|
|
threads = 20
|
|
jobs = 100
|
|
|
|
for i in range(threads):
|
|
w = Worker()
|
|
w.start()
|
|
|
|
for i in range(jobs):
|
|
queue.put(im)
|
|
|
|
for i in range(threads):
|
|
queue.put(None)
|
|
|
|
queue.join()
|
|
|
|
print()
|
|
print(time.time() - t0)
|
|
print(len(result), sum(result))
|
|
print(result)
|