Skip to content

Instantly share code, notes, and snippets.

@tkaemming
Created May 6, 2014 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkaemming/ef91d9a6d633fa0d8038 to your computer and use it in GitHub Desktop.
Save tkaemming/ef91d9a6d633fa0d8038 to your computer and use it in GitHub Desktop.
"""
Broken example.
"""
from cassandra.cluster import Cluster
from multiprocessing import Pool
size = 4
keyspace = 'system'
def executor(i):
cluster = Cluster()
session = cluster.connect(keyspace)
return list(map(list, session.execute('select * from schema_keyspaces;')))
if __name__ == '__main__':
pool = Pool(size)
for result in pool.imap_unordered(executor, xrange(0, size)):
print result
"""
Working example.
"""
from multiprocessing import Pool
size = 4
keyspace = 'system'
def executor(i):
from cassandra.cluster import Cluster
cluster = Cluster()
session = cluster.connect(keyspace)
return list(map(list, session.execute('select * from schema_keyspaces;')))
if __name__ == '__main__':
pool = Pool(size)
for result in pool.imap_unordered(executor, xrange(0, size)):
print result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment