Skip to content

Commit 2d04178

Browse files
sadovnychyihonzakral
authored andcommitted
Move import statement into a function
To fix a bug on App Engine where multiprocessing is not allowed. Closes elastic#282
1 parent 3e6ab22 commit 2d04178

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

elasticsearch/helpers/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import unicode_literals
22

33
import logging
4-
from multiprocessing.dummy import Pool
54
from operator import methodcaller
65

76
from ..exceptions import ElasticsearchException, TransportError
@@ -216,6 +215,9 @@ def parallel_bulk(client, actions, thread_count=4, chunk_size=500,
216215
should return a tuple containing the action line and the data line
217216
(`None` if data line should be omitted).
218217
"""
218+
# Avoid importing multiprocessing unless parallel_bulk is used
219+
# to avoid exceptions on restricted environments like App Engine
220+
from multiprocessing.dummy import Pool
219221
actions = map(expand_action_callback, actions)
220222

221223
pool = Pool(thread_count)

0 commit comments

Comments
 (0)