i am newbie in python and cassandra. i tried to use python multiproccessing in cassandra and i got it in this site https://github.com/aholmberg/driver-multiprocessing/blob/py3/multiprocess_execute.py how can i fix the error, please tell me if any change i must apply. and this is my code:
from multiprocessing import Pool
import sys
import time
from cassandra.cluster import Cluster
from cassandra.query import tuple_factory
def query_gen(n):
for _ in range(n):
yield ('local', )
class QueryManager(object):
batch_size = 10
def __init__( self , cluster , process_count = None ):
self.pool = Pool(processes=process_count, initializer=self._setup, initargs=(cluster,))
@classmethod
def _setup(cls, cluster):
cls.session = cluster.connect()
cls.session = cluster.connect('new')
cls.session.row_factory = tuple_factory
cls.prepared = cls.session.prepare('SELECT * FROM new.mytbl')
def close_pool( self ):
self.pool.close()
self.pool.join()
def get_results(self, params):
results = self.pool.map(_get_multiproc, params, self.batch_size)
return results
@classmethod
def _execute_request(cls, params):
return cls.session.execute(cls.prepared, params)
def _get_multiproc(params):
return QueryManager._execute_request(params)
if __name__ == '__main__':
try:
iterations = 1
processes = 2
except (IndexError, ValueError):
print("Usage: %s <num iterations> [<num processes>]" % 1)
sys.exit(1)
cluster = Cluster()
cluster = Cluster(['127.0.0.1'])
qm = QueryManager(cluster, processes)
start = time.time()
rows = qm.get_results(query_gen(iterations))
delta = time.time() - start
#print("%d queries in %s seconds (%s/s)" % (iterations, delta, iterations / delta))
and this is error log:
File "multi.py", line 64, in rows = m.get_results(query_gen(iterations))
File "multi.py", line 40, in get_results results = self.pool.map(_get_multiproc, params, self.batch_size)
File "/usr/lib/python2.7/multiprocessing/pool.py", line 251, in map return self.map_async(func, iterable, chunksize).get()
File "/usr/lib/python2.7/multiprocessing/pool.py", line 567, in get raise self._value
ValueError: Too many arguments provided to bind() (got 1, expected 0)