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) |
イテレーター使って回してもそんなに変わらないかな
$ python use-iter.py
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
pokotyamu 8238 48.9 0.2 2433900 27116 s008 S+ 2:57PM 0:00.31 python use-iter.py
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
pokotyamu 8238 1.5 0.2 2433900 27128 s008 S+ 2:57PM 0:00.32 python use-iter.py
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
pokotyamu 8238 0.0 0.2 2433900 27132 s008 S+ 2:57PM 0:00.32 python use-iter.py
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
pokotyamu 8238 0.0 0.2 2433900 27132 s008 S+ 2:57PM 0:00.32 python use-iter.py
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
pokotyamu 8238 0.0 0.2 2433900 27136 s008 S+ 2:57PM 0:00.32 python use-iter.py
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
pokotyamu 8238 0.0 0.2 2433900 27136 s008 S+ 2:57PM 0:00.33 python use-iter.py
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
pokotyamu 8238 0.0 0.2 2433900 27136 s008 S+ 2:57PM 0:00.33 python use-iter.py
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
pokotyamu 8238 0.0 0.2 2433900 27136 s008 S+ 2:57PM 0:00.33 python use-iter.py
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
pokotyamu 8238 0.0 0.2 2433900 27136 s008 S+ 2:57PM 0:00.34 python use-iter.py
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
pokotyamu 8238 0.0 0.2 2433900 27136 s008 S+ 2:57PM 0:00.34 python use-iter.py
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
print 関数消したら、更にいい感じになった。