Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ env:
matrix:
allow_failures:
- env: DJANGO="<1.7,>=1.6"
- python: "pypy"
- python: "pyp3"
install:
- pip install -U pip
- pip install .
Expand Down
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ Multi processing
It not only increased performance but the garbage collection
and therefore the huge memory footprint from previous versions.

**Note:** PyPy seems to have some problems regarding multiprocessing,
for that matter all multiprocessing is disabled in PyPy.


Testing
-------
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[pytest]
norecursedirs=venv
norecursedirs=venv env
DJANGO_SETTINGS_MODULE=tests.settings
addopts = --tb=short --pep8 --isort --flakes -rxs
pep8ignore=
Expand Down
58 changes: 41 additions & 17 deletions stdimage/management/commands/rendervariations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from stdimage.utils import render_variations

is_pypy = '__pypy__' in sys.builtin_module_names
BAR = None


Expand Down Expand Up @@ -43,24 +44,47 @@ def handle(self, *args, **options):
queryset = model_class._default_manager \
.exclude(**{'%s__isnull' % field_name: True}) \
.exclude(**{field_name: ''})
images = queryset.values_list(field_name, flat=True)

pool = Pool(
initializer=init_progressbar,
initargs=[queryset.count()]
images = queryset.values_list(field_name, flat=True).iterator()
count = queryset.count()

if is_pypy: # pypy doesn't handle multiprocessing to well
self.render_linear(field, images, count, replace)
else:
self.render_in_parallel(field, images, count, replace)

@staticmethod
def render_in_parallel(field, images, count, replace):
pool = Pool(
initializer=init_progressbar,
initargs=[count]
)
args = [
dict(
file_name=file_name,
variations=field.variations,
replace=replace,
)
for file_name in images
]
pool.map(render_field_variations, args)
pool.apply(finish_progressbar)
pool.close()
pool.join()

@staticmethod
def render_linear(field, images, count, replace):
init_progressbar(count)
args_list = [
dict(
file_name=file_name,
variations=field.variations,
replace=replace,
)
args = [
dict(
file_name=file_name,
variations=field.variations,
replace=replace,
)
for file_name in images
]
pool.map(render_field_variations, args)
pool.apply(finish_progressbar)
pool.close()
pool.join()
for file_name in images
]
for args in args_list:
render_variations(**args)
finish_progressbar()


def init_progressbar(count):
Expand Down