Last active
November 15, 2017 05:58
-
-
Save pokotyamu/de1de53a82cf25a92083807935ac701f to your computer and use it in GitHub Desktop.
fastimage を同期的に処理してみるテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from fastimage.detect import bytes_to_size | |
import os | |
import subprocess | |
import time | |
def test(url): | |
stream = requests.get(url, stream=True) | |
body = bytes() | |
for line in stream.iter_content(chunk_size=24): | |
body += line | |
image_size, image_type = bytes_to_size(body) | |
if image_size and image_type: | |
return {"size": image_size, "type": image_type} | |
if image_size is not None or image_type in ['bmp', 'tif']: | |
return | |
for _ in range(10): | |
print(subprocess.check_output(["ps", "u", str(os.getpid())]).decode('UTF-8').rstrip()) | |
url = "https://s3-ap-northeast-1.amazonaws.com/df-monkey-preview/testdata/images/300x800.jpg" | |
time.sleep(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from fastimage.detect import bytes_to_size | |
import os | |
import subprocess | |
import time | |
def test(url): | |
stream = requests.get(url, stream=True) | |
body = bytes() | |
chunk = stream.raw.read(24) | |
while chunk and len(body) < 3000000: | |
body += chunk | |
image_size, image_type = bytes_to_size(body) | |
if image_size and image_type: | |
return image_size, image_type | |
if image_size is not None or image_type in ['bmp', 'tif']: | |
return | |
chunk = stream.raw.read(8) | |
for _ in range(10): | |
print(subprocess.check_output(["ps", "u", str(os.getpid())]).decode('UTF-8').rstrip()) | |
url = "https://s3-ap-northeast-1.amazonaws.com/df-monkey-preview/testdata/images/300x800.jpg" | |
print(test(url)) | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
イテレーター使って回してもそんなに変わらないかな