Skip to content

Commit 59c5ef8

Browse files
author
Laurynas Butkus
committed
Do not use multiprocessing if max_parallel_uploads is less than 2
1 parent 789d3ed commit 59c5ef8

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

convertapi/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import multiprocessing
22

33
def map_in_parallel(f, values, pool_size):
4+
if pool_size < 2:
5+
return map(f, values)
6+
47
pool = multiprocessing.Pool(pool_size)
58
results = pool.map_async(f, values)
69
pool.close()

tests/test_convertapi.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
class TestConvertapi(utils.TestCase):
1111
def setUp(self):
1212
convertapi.api_secret = os.environ['CONVERT_API_SECRET']
13+
convertapi.max_parallel_uploads = 10
1314

1415
def test_defaults(self):
1516
eq_('https://v2.convertapi.com/', convertapi.base_uri)
@@ -23,6 +24,11 @@ def test_convert_file(self):
2324
assert result.save_files(tempfile.gettempdir())
2425
assert result.conversion_cost > 0
2526

27+
def test_convert_file_no_parallelizm(self):
28+
convertapi.max_parallel_uploads = 1
29+
result = convertapi.convert('pdf', { 'File': 'examples/files/test.docx' })
30+
assert result.save_files(tempfile.gettempdir())
31+
2632
def test_convert_file_alternative(self):
2733
result = convertapi.convert('pdf', { 'File': 'examples/files/test.docx', 'converter': 'openoffice' })
2834
assert result.save_files(tempfile.gettempdir())

0 commit comments

Comments
 (0)