From 2d0417821595af36a2cdd96649ce3ac93cd97fc6 Mon Sep 17 00:00:00 2001 From: Dmitry Sadovnychyi Date: Fri, 16 Oct 2015 13:06:07 +0800 Subject: [PATCH] Move import statement into a function To fix a bug on App Engine where multiprocessing is not allowed. Closes #282 --- elasticsearch/helpers/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/elasticsearch/helpers/__init__.py b/elasticsearch/helpers/__init__.py index 13bf623a..3578b873 100644 --- a/elasticsearch/helpers/__init__.py +++ b/elasticsearch/helpers/__init__.py @@ -1,7 +1,6 @@ from __future__ import unicode_literals import logging -from multiprocessing.dummy import Pool from operator import methodcaller from ..exceptions import ElasticsearchException, TransportError @@ -216,6 +215,9 @@ def parallel_bulk(client, actions, thread_count=4, chunk_size=500, should return a tuple containing the action line and the data line (`None` if data line should be omitted). """ + # Avoid importing multiprocessing unless parallel_bulk is used + # to avoid exceptions on restricted environments like App Engine + from multiprocessing.dummy import Pool actions = map(expand_action_callback, actions) pool = Pool(thread_count)