Skip to content

Instantly share code, notes, and snippets.

@arodrime
Created April 7, 2014 12:12
Show Gist options
  • Save arodrime/10019138 to your computer and use it in GitHub Desktop.
Save arodrime/10019138 to your computer and use it in GitHub Desktop.
[...]
def forked_call(pagination_counts, pagination_standard, keys, timeout, num_nodes):
#Connection to Cassandra
connection = cassandraHelpers.ConnectAndOpenSession(timeout=timeout, executor_threads=num_nodes)
session = connection['session']
print(len(keys))
def go_threads(workers, keys, pagination_counts, pagination_standard, timeout, num_nodes):
pool = Pool(processes=workers)
list_of_partitions = chunks(keys, workers)
for l in list_of_partitions:
pool.apply_async(forked_call, args=(pagination_counts, pagination_standard, l, timeout, num_nodes))
pool.close()
pool.join()
[...]
#In cassandraHelpers.py file
[...]
def ConnectAndOpenSession(servers=SERVERS, keyspace=KEYSPACE, timeout=10.0, row_factory=named_tuple_factory, connection_class=LibevConnection, executor_threads=3):
try:
cluster = Cluster(servers, executor_threads=executor_threads)
cluster.connection_class = connection_class
session = cluster.connect(keyspace)
session.row_factory = row_factory
session.default_timeout = timeout
return {'cluster': cluster, 'session': session}
except:
print "ERROR: Unknown error connecting the server"
traceback.print_exc()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment