21
21
from threading import Condition
22
22
import sys
23
23
24
- from cassandra .cluster import ResultSet
24
+ from cassandra .cluster import ResultSet , EXEC_PROFILE_DEFAULT
25
25
26
26
import logging
27
27
log = logging .getLogger (__name__ )
28
28
29
29
30
30
ExecutionResult = namedtuple ('ExecutionResult' , ['success' , 'result_or_exc' ])
31
31
32
- def execute_concurrent (session , statements_and_parameters , concurrency = 100 , raise_on_first_error = True , results_generator = False ):
32
+ def execute_concurrent (session , statements_and_parameters , concurrency = 100 , raise_on_first_error = True , results_generator = False , execution_profile = EXEC_PROFILE_DEFAULT ):
33
33
"""
34
34
Executes a sequence of (statement, parameters) tuples concurrently. Each
35
35
``parameters`` item must be a sequence or :const:`None`.
@@ -56,6 +56,9 @@ def execute_concurrent(session, statements_and_parameters, concurrency=100, rais
56
56
footprint is marginal CPU overhead (more thread coordination and sorting out-of-order results
57
57
on-the-fly).
58
58
59
+ `execution_profile` argument is the execution profile to use for this
60
+ request, it is passed directly to :meth:`Session.execute_async`.
61
+
59
62
A sequence of ``ExecutionResult(success, result_or_exc)`` namedtuples is returned
60
63
in the same order that the statements were passed in. If ``success`` is :const:`False`,
61
64
there was an error executing the statement, and ``result_or_exc`` will be
@@ -90,17 +93,19 @@ def execute_concurrent(session, statements_and_parameters, concurrency=100, rais
90
93
if not statements_and_parameters :
91
94
return []
92
95
93
- executor = ConcurrentExecutorGenResults (session , statements_and_parameters ) if results_generator else ConcurrentExecutorListResults (session , statements_and_parameters )
96
+ executor = ConcurrentExecutorGenResults (session , statements_and_parameters , execution_profile ) \
97
+ if results_generator else ConcurrentExecutorListResults (session , statements_and_parameters , execution_profile )
94
98
return executor .execute (concurrency , raise_on_first_error )
95
99
96
100
97
101
class _ConcurrentExecutor (object ):
98
102
99
103
max_error_recursion = 100
100
104
101
- def __init__ (self , session , statements_and_params ):
105
+ def __init__ (self , session , statements_and_params , execution_profile ):
102
106
self .session = session
103
107
self ._enum_statements = enumerate (iter (statements_and_params ))
108
+ self ._execution_profile = execution_profile
104
109
self ._condition = Condition ()
105
110
self ._fail_fast = False
106
111
self ._results_queue = []
@@ -132,7 +137,7 @@ def _execute_next(self):
132
137
def _execute (self , idx , statement , params ):
133
138
self ._exec_depth += 1
134
139
try :
135
- future = self .session .execute_async (statement , params , timeout = None )
140
+ future = self .session .execute_async (statement , params , timeout = None , execution_profile = self . _execution_profile )
136
141
args = (future , idx )
137
142
future .add_callbacks (
138
143
callback = self ._on_success , callback_args = args ,
0 commit comments